Return to main?

Hey guys..
I'm having a little issue figuring out how to get my program to restart if a wrong parameter is entered.
Can anyone point me in the right direction?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    // Write a program that allows the user to enter the grade scored in a programming class (0-100).
    // If the user scored a 100 then notify the user that they got a perfect score.

#include <iostream>

using namespace std;
void getScore(int);

int main()
{

    cout << "Enter testscore: ";
    int testScore;
    cin >> testScore;
    if(testScore <= 100 && testScore >= 0)
    {
        getScore(testScore);
    } else
    {
        cout << "Sorry dude, you entered a wrong score, try again: ";
        // What to enter in order to start over??
    }

}

void getScore(int x) // Function to print out the students testscore.
{
    if(x >= 90 && x <= 100) cout << "\n\n\n\tYou got an A. \n\n\n\tCONGRATZ!\n\n\n" << endl;

    if(x >= 80 && x <= 89) cout << "\n\nYou scored a B!\n\n" << endl;

    if(x >= 70 && x <= 79) cout << "\n\nYou scored a C!\n\n" << endl;

    if(x >= 60 && x <= 69) cout << "\n\nYou scored a D!\n\n" << endl;

    if(x >= 0 && x <= 59) cout << "\n\nYou scored a F\n\n" << endl;
}


Regards
The simplest way is a while loop :

1
2
3
4
5
6
7
8
9
    cout << "Enter testscore: ";
    int testScore;

    while( cin >> testScore && !(testScore <= 100 && testScore >= 0) ) {
        cout << "Sorry dude, you entered a wrong score, try again: ";
    }


    getScore(testScore);


Arh!
It can be so easy when you see it. But figuring it out before seemed so hard :S

Thanks alot, man
Topic archived. No new replies allowed.