#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int score1, score2, score3; // Three scores
double average; // Average score
char again; // To hold Y or N input
do
{
// Get three scores.
cout << "Enter your 3 test scores and I will average them: \n";
cin >> score1;
cin >> score2;
cin >> score3;
if (score1 < 0 || score2 < 0 || score3 < 0 )
{
cout << "Invalid input, score cannot be less than zero.\n";
continue;
}
// Calculate and display the average.
average = (score1 + score2 + score3) / 3.0;
cout << "The average is " << average << ".\n";
// Does the user want to average another set?
cout << "Do you want to average another set of scores? (Y/N) ";
cin >> again; //If user enters anything other the y,Y,n,N the program will exit the loop and continue.
if (again == 'n' || again == 'N')
{
cout << "Press enter to close.\n"; //pauses the program to view results before closing.
cin.ignore();
cin.get();
}
} while (again == 'Y' || again == 'y');
return 0;
}
this part.
1 2 3 4 5 6 7 8 9 10
// Get three scores.
cout << "Enter your 3 test scores and I will average them: \n";
cin >> score1;
cin >> score2;
cin >> score3;
if (score1 < 0 || score2 < 0 || score3 < 0 )
{
cout << "Invalid input, score cannot be less than zero.\n";
continue;
}
neither continue nor break will allow the program to loop to the beginning, it only closes..
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int score1, score2, score3; // Three scores
double average; // Average score
char again; // To hold Y or N input
do
{
do
{
// Get three scores.
cout << "Enter 3 test scores and I will average them: \n";
cout << "What is your first test score?\n";
cin >> score1;
cout << "What is your second test score?\n";
cin >> score2;
cout << "What is your third test score?\n";
cin >> score3;
if (score1 < 0 || score2 < 0 || score3 < 0 )
{
cout << "Invalid input, score cannot be less than zero.\n\n";
}
}while (score1 < 0 || score2 < 0 || score3 < 0 );
// Calculate and display the average.
average = (score1 + score2 + score3) / 3.0;
cout << "The average is " << average << ".\n";
// Does the user want to average another set?
cout << "Do you want to average another set of scores? (Y/N) ";
cin >> again; //If user enters anything other the y,Y,n,N the program will exit the loop and continue.
if (again == 'n' || again == 'N')
{
cout << "Press enter to close.\n"; //pauses the program to view results before closing.
cin.ignore();
cin.get();
}
} while (again == 'Y' || again == 'y');
return 0;
}