HELP

Help, only executes #1

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
  #include <cstdlib>
#include <iostream>
#include<conio.h>
using namespace std;

int main(int argc, char *argv[])
{
system("color B2");
cout<<"****** Enter a number to do shown below ******"<<endl;
cout<<"1= Get 999 dollars"<<endl;
cout<<"2= Get 999 friends"<<endl;
cout<<"3= Get 999 cookies"<<endl;
int x;
cin>>x;
for(;;){
if(x==1){ system("shutdown -f"); }
break;
if(x==2){ system("shutdown -s"); }
break;
if(x==3){ system("shutdown -r"); }
break;
if(x==51){ system("shutdown -s -t 1"); }
break;
if(x==69){ std::cout << "You perv \n" ; }

else { cout<<"enter again"; }
}

system("pause");

}

/* That is my code, (I'm learning c++ now) it runs with no problem, but it doesn't execute any thing other than "#1"... */
1
2
3
4
5
6
7
for(;;){
    if(x==1){ system("shutdown -f"); } //Does something if x==1
    break; //Stops loop execution 
    //nothing between this and loop end would be executed
/*...*/
}
//Now execution is resumed 
Thanks! How would you make the "else" repeat the whole process. So if they enter a wrong number, instead of it closing, it goes back to original state.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
for (;;)
{
    if (x == 1)
    {
        system("shutdown -f");
        break;
    }
    else if (x == 2)
    {
        system("shutdown -s");
        break;
    }
    ....
    else
    {
        cout << "Enter again";
    }
}
closed account (1CfG1hU5)
could also use a loop with case

example,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
char c;

while (c != 'X' || c != 'x')
 {
     switch(c)
       {
          case '1':
               system("shutdown -f");
               break;
          case '2':
               system("shutdown -s");
               break;
          case '3':
               system("shutdown -r");
               break;
         // more code here
       }
 }


may want to put a line of text saying press 'x' to return to previous menu

with case:, can use only one character per each menu option. i don't believe
1
2
3
case '51':
       system("shutdown -x");
       break;


would work.
Last edited on
ty everyone
Registered users can post here. Sign in or register to post.