How would I control the data range to ensure a mark entered was between 0 and 100, if it is less than 0 and greater than 100 it is invalid. I know this can be done using IF statements but I'm not sure how to go about it. Thanks.
Something like this should do. It uses a while loop + if statements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
int main ()
{
usingnamespace std;
int mark[5];
for (int i = 0; i < 5; i++)
{
do
{
cout << "enter mark " << i << ": ";
cin >> mark[i];
}
while (mark[i] < 0 || mark[i] > 100);
}
}
// Prompt the user with "prompt" and then read an int from cin. Repeat if they enter a non-integer, or an int outside the range [low, high). Returns the valid int.
int getInt(constchar *prompt, int low, int high)