vendredi 5 octobre 2018

C++ If statement, repeating from else

Just started C++ at university so I've decided to try and do a classic 'shop project' using C++.

I'm just wandering if there is any way to repeat an if statement from the else. For example in the code I'm asking the user if the would like help browsing the shop and if they reply yes then it shows them the options, if they reply no then it continues with the code, however if it isn't yes or no then the code tells the user it can't understand the user.

What I am asking is can I get the user to input the value again and it re-run the if statement without using a loop, or do I have to use a loop?

Here's the bit of code:

cin >> help;
if (help == "Yes" || help == "yes")
{
    cout << "These are out current sections that you are able to browse:" << endl;
    cout << "-Offers and Deals (1) \n-Computing (2) \n-Console (3) \n-Audio (4) \n-Electronic Displays (5) \n-Cabling (6) \n-General Accessories (7)" << endl;
}
else if (help == "No" || help == "no")
{
    cout << "You have chosen not to look at our browsing list." << endl;
}
else
{
    cout << "Sorry the system does not understand what you have entered. \n Please use full English (Yes/No)." << endl;

}

If anyone could help me with this, that would be great. I know its simple code and probably a lot more efficient ways of doing it, just using the ways ive currently been taught at university so far.

Thank in advance.

Aucun commentaire:

Enregistrer un commentaire