stuck on understanding system (cls);

Hi i am kinda new to programming but am getting better at it and i am stuck on understanding the system ("cls"); function. i was told i could use it in a while loop and then clear it out and reappear on the screen when a correct choice is inputted. I've done a switch statement and used the clear function but in a while loop i don't understand how i can make a menu reappear. can some one just help me understand the system ("cls"); part.
Last edited on
First of all, system( "cls" ); is just a command that CLEARS the screen, nothing more, *nothing less*.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i was told i could use it in a while loop and then clear it out and reappear on the screen when a correct choice is inputted


maybe you mean if an incorrect choice is inputted ?

yes you can, some people do it to not mess up the screen. something like :
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
// ...
int choice;

cout << "Choose your beverage" << endl;
cout << "1. Coke" << endl;
cout << "2. Sprite" << endl;
cout << "3. Coffee" << endl; // ??

cout << "Enter your choice: ";
cin >> choice;

while( choice != 1 || choice != 2 || choice != 3 ) {
    cin.ignore();
   
    system( "cls" ); // clear the screen and prompt again if the choice is invalid
                             // so the screen will not mess up...
    cout << "Choose your beverage" << endl;
    cout << "1. Coke" << endl;
    cout << "2. Sprite" << endl;
    cout << "3. Coffee" << endl; // ??

    cout << "Enter your choice: ";
    cin >> choice;
}
// ... 



Hope this helps, just ask again if you have questions...
You shouldn't use system("anything")
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.