Program doesn't work! Need Help!

So i've made a program which is suppose to allow the user to play rock-paper-scissors-lizard-Spock against the computer. However I can't seem to get the program to work any feedback would be greatly appreciated!

Last edited on
Line 15: srand(unsigned(time(NULL))); should be BEFORE your loop, otherwise, you're going to generate the same random numbers each time though the loop.

Lines 32-41: You need { } around your cout statements. Otherwise, only the first cout statement is executed conditionally. The remainder are executed unconditionally.

What do you mean by "I can't seem to get it to work"? It runs. Whether it prduces the results you intended is hard to say since you don't display the computer's choice.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/


Thanks, for the feedback. Sorry about the formatting this was my first post, but I'll definitely post it the proper way next time.

However, I am still having problems with generating random responses to when the user wins, loses or ties the computer. It seems all of the responses show up at once when compiled.
1
2
3
4
5
6
7
8
9
if (msgNum==0)
{
msgNum= rand()% 5;
cout <<"Congradulations you won against the computer! "<<endl;
cout <<"OMG you just won, hip hip hurrayyyyyyyyyyy! "<<endl;
cout <<" Winner Winner Winner!"<<endl;
cout << "You win!"<<endl;
cout <<"You just won against Sheldon Cooper!"<<endl;
}

You do realize that is going to display all 5 lines every time?
By the presense of line 3, I assume you meant to display only one of the lines. To do that you'll need a switch statement.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (msgNum==0)
{   msgNum= rand()% 5;
    switch (msgnum)
    {
    case 0: cout <<"Congradulations you won against the computer! "<<endl;
                 break;
    case 1: cout <<"OMG you just won, hip hip hurrayyyyyyyyyyy! "<<endl;
                 break;
    case 2: cout <<" Winner Winner Winner!"<<endl;
                break;
    case 3: cout << "You win!"<<endl;
                break;
    case 4: cout <<"You just won against Sheldon Cooper!"<<endl;
                 break;
    }
}



perfect thanks a lot mate!
Topic archived. No new replies allowed.