What kind of loop are you trying to do?
The while-loop, do-while loop, or the for loop. My assumption is the do-while loop.
Example of the while loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// This program demonstrates a simple while loop.
#include <iostream>
usingnamespace std;
int main()
{
int number = 0;
while (number < 5)
{
cout << "Hello\n";
number++;
}
cout << "That's all!\n";
return 0;
}
// This program averages 3 test scores. It repeats as
// many times as the user wishes.
#include <iostream>
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 3 scores and I will average them: ";
cin >> score1 >> score2 >> score3;
// 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? (Y/N) ";
cin >> again;
} while (again == 'Y' || again == 'y');
return 0;
}