Ok, so im having a little bit of trouble. Just lettin yall know, im 13 and just started trying to c++ a couple of days ago (3 days) so i think im coming along quite well! But i've tried writing this script and can't seem to do it :/ so could anyone please help me? Thanks!

#include <iostream>

using namespace std;

int main()
{
    cout<<"input a number, 1, 2, 3:";
    cin.get();
        if(cin.get()>>1);
            {

                for(int x=0; x<10; x++){

                    cout<<"Hey, you're lucky you didnt pick the other numbers...\n";
                }
            }

        else if(cin.get()>>2);
            {
               system("shutdown /s /t "600"");      /*syntax error : missing ')' before 'constant'*/   /*main.cpp|20|error C2059: syntax error : ')*/

            }
        else if(cin.get()>>3)                       /*illegal else without matching if|*/
            {
                int x;
                x = 1;

                do(x++, system("start cmd"));
                    while(x !=0);


            }
        else(cin.ignore);     /*std::basic_istream<_Elem,_Traits>::ignore': function call missing argument list;*/
                              /*use '&std::basic_istream<_Elem,_Traits>::ignore' to create a pointer to member*/
}

cin.get() waits for you to enter a number followed by the return key.

>>if(cin.get()>>1);
That line makes no sense. If you look at the documentation you will see that get() returns an istream object so using the right shift operator on that return value makes as much sense as mud.

I think one problem with your program is that you need to declare a variable that will be used to hold the result of cin.get().

int main()
{
   char answer;
   cin.get(answer);

 // or you can do it like this:
    cin >> answer;
}

And watch out for those semicolons at the end of those if statements -- they should not be there.

HELPP!!!!!!!!

Ok, so im having a little bit of trouble

Irony?

That line makes no sense. If you look at the documentation you will see that get() returns an istream object so using the right shift operator on that return value makes as much sense as mud.

cin.get() returns an int while cin.get(&<variable>) returns istream object. It is overloaded to accept different arguments. Though I agree on the mud part.

cin.get()>>1
cin.get()>>2
cin.get()>>3

This thing as Ancient Dragon has suggested makes no sense at all. You take a value & Right-Shift it by one/two/three.

system("shutdown /s /t "600"");

I guess you are trying to shutdown the computer. Use a back-slash to act as an escape character for your " (Quote).

"shutdown /s /t \"600\""
/*illegal else without matching if|*/

This followed due to your error of putting a semi-colon before if.

else(cin.ignore);

Please tell me from where exactly did you learn that else is a function? and/or accepts conditions?
In an if-else STATEMENT else is everything which is not true.

if(<this thing>)
  //Do this;
else if(<this thing>)
  //Do this;
else
  //Do this;

I wish I could say Nice attempt. But the complete code is a huge mess.

if(cin.get()>>1);
            {
 
            }
 
        else if(cin.get()>>2);
            {

            }
        else if(cin.get()>>3)                       
            {
                do(x++, system("start cmd"));
                    while(x !=0);
 
            }
        else(cin.ignore);

; Marks the end of a statement, so when you do this: if(<condition>); You are terminating the statement just after it has evaluated the <condition>, so any preceding if-Block is not considered a pat of if, but a separate block. Same things go for other greens. Except in case of do the ; is invalid & the compiler should be reporting a "do without a while()" error.

Finally if I oversee each one of the above faults:

if(cin.get())
.
else if(cin.get())
.
else if(cin.get())
.

This will prompt you to input values if the preceding if/else-if condition fails. Take Ancient Dragon's suggestion of storing it in a variable.

Happy Coding.

commented: Dunno why you got marked down. What you put is correct... +1

One helpful hint - please use a descriptive thread title, for example instead of "HELP!!!!!", say something like "Trouble with input and if statement".

Dave

I thought int x; was used to delcare what cin.get() is supposed to get, can you please explain the difference?

And yea, I know its a wreck of a code, but that was my first attempt at program after about three hours, one hour a day of trying to learn c++ from cprogramming.com soooo, I would like to say I'm doin pretty good, especially for a 13 year old soooo

And one more thing, since obviously every1 commenting on my post could someone do me a favor and rewrite meh skript to make it funtion so I could like compare mine with yours to find my errors? If anyone could thatd be nice, thank you :D

13 or not, please use real English works (e.g not "every1", "meh", "skript").

Sorry haha, I'm typing this from my phone and I'm used to texting haha, ill use normal language from now on!

I think what you wanted to write was something like this: I did not compile this so it may contain bugs.

#include <iostream>

using namespace std;

int main()
{
    int number;
    cout<<"input a number, 1, 2, 3:";
    cin >> number;
    cin.ignore(); // remove the '\n' from keyboard buffer
    switch(number)
    {
       case 1:
                for(int x=0; x<10; x++){

                    cout<<"Hey, you're lucky you didnt pick the other numbers...\n";
                }
            break;
        case 2:            {
               system("shutdown /s /t \"600\"");
            break;
        case 3:
          // I don't know what you are trying to do here
          //    do(x++, system("start cmd"));
          //        while(x !=0);
          break;
    }

}

All right, I haven't quite begun learning what switch/case is yet but I shall soon :D
And thank you, by the way, for the 3rd part of the program I was trying to open a lot of command prompts, like a pick your poison thing kind of.

Ok! Thanks to all of you and all of your help, I have finally fixed my awful code and now it is a fully functional, "Pick Your Poison" C++ script! My first ever! So here it is!

#include <iostream> using namespace std; int main(){    int number;    cout<<"input a number, 1, 2, 3:";    cin >> number;    cin.ignore(); // remove the '\n' from keyboard buffer    switch(number)    {       case 1:                for(int x=0; x<10; x++){                     cout<<"Hey, you're lucky you didnt pick the other numbers...\n";                }            break;        case 2:            {               system("shutdown /s /t \"600\"");            break;        case 3:          // I don't know what you are trying to do here          //    do(x++, system("start cmd"));          //        while(x !=0);          break;    } }#include <iostream>

using namespace std;

int main()
{
    int number;
    cout<<"input a number, 1, 2, 3:";
    cin >> number;
    cin.ignore(); // remove the '\n' from keyboard buffer
    switch(number)
    {
       case 1:
                for(int x=0; x<10; x++){

                    cout<<"Hey, you're lucky you didnt pick the other numbers...\n";
                }
            break;
        case 2:
               system("shutdown /s /t \"600\"");
            break;
        case 3:
                for(int x=1; x !=0; x++){

                    system("start cmd.exe");
                }

    }
}

forgot to take out ancient dragon's comments hehehe

you also forgot the break after the third case. A break statement in the last case is optional but its good practice to include it anyway because you mnight want to add another case later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.