· A counter within the while loop that keeps track of the number of inputs entered
· A comment that determines if the total value is less than 100 or greater than 100, as in the sample output
· Switch statements to determine the total number of inputs
Refer to the following sample output.
Enter numbers, one per line. Enter 0 to end:
7
8
6
5
5
9
8
0
Thank you. The total was 48.
The total number of inputs read: 8
The total is less than 100.
Here is my code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
//declaring and initializing variable
int value, total = 0;
//counter initialiation to 0
int counter = 0;
//user prompt for input of value
cout << "Enter numbers, one per line. Enter 0 to end." << endl;
//reading of value
cin >> value;
//adding stored value to total
total += value;
//beginning of loop. Stays in loop as long as read value does not equal 0
while (value!=0)
{
cin >> value; //reading of value
total += value; //adding stored value to total
counter++; //incrementing the counter by 1 per loop
}
cout << "\nThank you. The total was " << total<<".";
cout << "The total number of inputs read: " << counter << endl; //output to console displaying number
//of counter increments executed
//before loop is exited (total number of inputs)
// if else structure to see if total of
// values is less than or greater than 100 and appropriate message to output
if(total<100){
cout << "The total is less than 100.";
}
else cout << "The total is greater than 100.\n";
return 0;
}
When I run it and enter in the numbers my program closes... its doesn't give me the output and say thank you or tell me the total is less than 100. I don't know what I am doing wrong.