include using namespace std int main int num cout
#include <iostream>
using namespace std;
int main()
{
int num;
cout << endl << \"Enter numbers, 999 to quit\" << endl; //1 - START
cin >> num; //1 - START
while (num != 999) //2 - TEST
{
cout << \"Number entered is: \" << num << endl; //3 - ACTION
cout << \"Enter numbers, 999 to quit\" << endl; //4 - RESTART
cin >> num; //4 - RESTART
}
return 0;
}
Type in the above program, compile and run.
Add the steps to total the numbers entered.
Add the steps to count how many numbers were entered.
Add the steps to compute the average.
Test with values you know the answer to.
Be sure and test for no values entered and make the appropriate correction to you code.
Solution
#include <iostream>
using namespace std;
int main()
{
int num,sum=0,count=0;
float avg=0;
cout << endl << \"Enter numbers, 999 to quit\" << endl; //1 - START
cin >> num; //1 - START
while (num != 999) //2 - TEST
{
cout << \"Number entered is: \" << num << endl; //3 - ACTION
sum+=num;
cout << \"Enter numbers, 999 to quit\" << endl; //4 - RESTART
cin >> num; //4 - RESTART
count++;
}
cout<<\"Total sum of entered number is \"<<sum<<endl;
cout<<\"Total number of elements entered is \" <<count <<endl;
cout<<\"Average = \"<<(float)sum/count<<endl;
return 0;
}

