FINISH THE PROGRAM C Program Count prompts for the number o

 FINISH THE PROGRAM C++ // Program Count prompts for the number of integers to sum. // It then reads the integers in a loop, summing them. // Finally, it prints the sum.  #include <iostream> using namespace std;  int main () {     int  sum = 0;                 // summing variable     int  dataValue;               // input value      // add an int declaration statement here for the loop counter      // add an int declaration statement here for the loop total      // add an assignment statement here to set the loop counter to 0      // add a cout statement here to prompt the user how many numbers     //     he/she wants to add i.e. the loop total      // add a cin statement here to get the loop total      // add a while statement here to test the loop counter     //       against the loop total   e.g. while (loopctr < looptotal)     //       Note: the variable names depend on how you declared them.      {         cout  << \"Enter an integer value.  Press return.\" << endl;         cin  >> dataValue;         sum = sum + dataValue;          // add a statement here to increment your counter variable       }  // end of while loop      cout  << endl << \"The sum is \"  << sum  << endl;     return 0; } 

Solution

#include <iostream>
using namespace std;

int main ()
{
int sum = 0; // summing variable
int dataValue; // input value

// add an int declaration statement here for the loop counter

// add an int declaration statement here for the loop total

// add an assignment statement here to set the loop counter to 0

// add a cout statement here to prompt the user how many numbers
// he/she wants to add i.e. the loop total

// add a cin statement here to get the loop total

// add a while statement here to test the loop counter
// against the loop total e.g. while (loopctr < looptotal)
// Note: the variable names depend on how you declared them.
int n;
cout<<\"Enter the number of intergers you would like to add:\";
cin>>n;
int i=0;
while(i<n)
{
cout << \"Enter an integer value and press return:\";
cin >> dataValue;
sum = sum + dataValue;

// add a statement here to increment your counter variable
i++;

// end of while loop
}
cout << endl << \"The sum is \" << sum << endl;
return 0;
}

 FINISH THE PROGRAM C++ // Program Count prompts for the number of integers to sum. // It then reads the integers in a loop, summing them. // Finally, it prints

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site