ELSE PROBLEM!

Okay. I'm completely new to c++. I've come across a problem I don't know how to solve. When someone makes a choice, I want the else, to just ask them the question again, so if i'm making something long, they don't have to completely restart.

Your question doesn't really make sense...do you have a small code sample that could show me what you want?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int choice;
    cout << "Type 1 or 2. ";
    cin >> choice;
    if( choice == 1 ) {
        cout << "\n1!";
        }
    else if( choice == 2 ) {
         cout << "\n2!";
         }
    else  {
      cout << "\nTHAT WASN'T A CHOICE!\n";
    }
                  
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


I don't want to have to end it. Is there anyway I can make it just ask the question again?
Use a while loop or something similar:

1
2
3
4
5
6
7
8
9
while(true) {
    cin>>choice;
    if(choice == 1) {
        //...
        return 0;
    } else {
        cout<<"incorrect choice";
    }
}


If you want to chain a bunch of relevant questions in a row (like ones that depend on the answer to a previous question), it will get more complicated.
Okay. Thanks a lot! ^^
Topic archived. No new replies allowed.