samedi 26 janvier 2019

How do I get my function to return to a specific point in my program in an if statement?

I want my function to work so that if someone enters more grades than the 20 allowed it returns to another point, whether in the function or out of it, so that the user has the option to try again. What do I need to change, I know return can't be the answer as it just exists the function and goes to the next line after the function call. This is for homework, and I'm honestly not sure this is even necessary, I just want it to be clean and handle user errors.

(Also, ctrl+k doesn't work on the main page for indenting my code, it's only on the "review your question" page that it works. What can I do?)

void gradeTaker()
{
    cout << "You may input up to 20 grades. \n";
    cout << "First enter the number of grades you have: \n";
    cin >> gradeCounted;
    if (gradeCounted > arraySize)
    {
        cout << "You entered a number of grades greater than 20, try again \n";
        return;
    }

The current result of my code is it exits the function and continues to the following line. I don't know the code necessary for what I want.

Aucun commentaire:

Enregistrer un commentaire