How do i get this code to loop infinitely until the user tells it to stop?
# include <iostream>
# include <cmath>
using namespace std;
double average, sd, s1, s2, s3, s4, deviation;
int main()
{
cout << "Press enter after entering a value.\n";
cout << endl;
cout << "Enter score one: ";
cin >> s1;
cout << "\nEnter score two: ";
cin >> s2;
cout << "\nEnter score three: ";
cin >> s3;
cout << "\nEnter score four: ";
cin >> s4;
average =(s1+s2+s3+s4)/4;
deviation =(((s1-average)*(s1-average))+((s2-average)*(s2-average))+((s3-average)*(s3-average))+((s4-average)*(s4-average)))/3;
sd = sqrt(deviation);
cout << "\nThe average of your four scores is "<<average<<".\n";
cout << "The standard deviation of your scores is "<<sd<<".\n";
return 0;
}
what i mean is that i would like the user to be able to repeat the program. i would like the user to be able to input different scores each time. This would happen over and over again until the user wanted to stop. For instance,
average
mean
"would you like to run the program again? y or n"
then they would hit "y" as long as they wanted to use the program. when they want to quit, they would hit "n"



LinkBack URL
About LinkBacks


