If Else Identifier not regstering

For this program I'm supposed to show the winnings in a game. However I don't think I've written the If Else connectors correctly as I keep getting the error "52: expected identifier before '(' token" Here's what I already have written:

/****************************************************************************
This program works to determine the winnings of a player in a game of chance.
The player will be prompted a random number generator will tell them what the
dice rolled to. Then the program will determine whether or not they won and
how much the won. The rules of the game are as follows:
A player places a bet of $5.00
All three dice are sixes : player wins $50.
All three dice are the same (but not sixes): player wins $20.
Any two of the dice are the same: player wins $5.00.
None of the dice are the same: player loses $5.00 bet!
*****************************************************************************/

#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
int roll1;
int roll2;
int roll3;

cout<<"This program will randomly generate three dice rolls.\n";
cout<<"These rolls will be played in the game and the program\n";
cout<<"will tell you what you have won or lost. The Rules are:\n";
cout<<"A player places a bet of $5.00\n";
cout<<"All three dice are sixes : player wins $50.\n";
cout<<"All three dice are the same (but not sixes): player wins $20.\n";
cout<<"Any two of the dice are the same: player wins $5.00.\n";
cout<<"None of the dice are the same: player loses $5.00 bet!\n"<<endl<<endl;

srand(time(NULL));
cout<<"Roll the first die by pressing the key when promted.\n";
system("PAUSE");
roll1 = rand ()%6 + 1;
cout<<"Roll the second die by pressing the key when promted.\n";
system("PAUSE");
roll2 = rand ()%6 + 1;
cout<<"Roll the third die by pressing the key when promted.\n";
system("PAUSE");
roll3 = rand ()%6 + 1;

cout<<"\n\nYour first roll was "<<roll1<<endl;
cout<<"Your second roll was "<<roll2<<endl;
cout<<"Your third roll was "<<roll3<<endl<<endl<<endl;

if(roll1==roll2) and (roll2==roll3)
{
if (roll1 == 6)
cout<<"You Win $50!\n";
else
cout<<"You Win $20!\n";
}
else if (roll1==roll2) and (roll1!=roll3) or (roll2==roll3) and (roll2!=roll1) or (roll1==roll3) and (roll1!=roll2)
{
cout<<"You Win $5!\n";
}
else (roll1!=roll2) and (roll1!=roll3) and (roll2!=roll3)
{
cout<<"You Lose $5\n";
}

system("Pause");
return 0;
}

I'm not looking to necessarily get the right answer but an explanation of why it's not reading that identifier "if" would help a lot. Thannks!
closed account (28poGNh0)
Good game you have body

This I suggest

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# include <iostream>
# include <iomanip>
# include <cstdlib>
# include <ctime>

using namespace std;

int main()
{
    int roll1;
    int roll2;
    int roll3;

    cout << "This program will randomly generate three dice rolls.\n";
    cout << "These rolls will be played in the game and the program\n";
    cout << "will tell you what you have won or lost. The Rules are:\n";
    cout << "A player places a bet of $5.00\n";
    cout << "All three dice are sixes : player wins $50.\n";
    cout << "All three dice are the same (but not sixes): player wins $20.\n";
    cout << "Any two of the dice are the same: player wins $5.00.\n";
    cout << "None of the dice are the same: player loses $5.00 bet!" << endl << endl << endl;

    srand(time(NULL));
    cout<<"Roll the first die by pressing the key when promted.\n";

    roll1 = rand ()%6 + 1;
    cout<<"Roll the second die by pressing the key when promted.\n";

    roll2 = rand ()%6 + 1;
    cout<<"Roll the third die by pressing the key when promted.\n";

    roll3 = rand ()%6 + 1;

    cout<<"\n\nYour first roll was "<<roll1<<endl;
    cout<<"Your second roll was "<<roll2<<endl;
    cout<<"Your third roll was "<<roll3<<endl<<endl<<endl;

    if(roll1==roll2&&roll2==roll3)
    {
        if (roll1 == 6)
            cout<<"You Win $50!\n";
        else
            cout<<"You Win $20!\n";
    }
    else if((roll1==roll2&&roll1!=roll3)||(roll2==roll3&&roll2!=roll1)||(roll1==roll3&&roll1!=roll2))
        cout<<"You Win $5!\n";
    else if(roll1!=roll2&&roll1!=roll3&&roll2!=roll3)
        cout<<"You Lose $5\n";

    return 0;
}
Thank you! I think I understand where I made the error!
Hi William, for future reference, if you are outputting multiple lines to a console, like you are in your example (quoted below):

1
2
3
4
5
6
7
8
 cout << "This program will randomly generate three dice rolls.\n";
    cout << "These rolls will be played in the game and the program\n";
    cout << "will tell you what you have won or lost. The Rules are:\n";
    cout << "A player places a bet of $5.00\n";
    cout << "All three dice are sixes : player wins $50.\n";
    cout << "All three dice are the same (but not sixes): player wins $20.\n";
    cout << "Any two of the dice are the same: player wins $5.00.\n";
    cout << "None of the dice are the same: player loses $5.00 bet!" << endl << endl << endl;


You can simply have 1 cout statement & write it like the following:
1
2
3
4
5
6
7
8
cout  << "This program will randomly generate three dice rolls.\n"
      << "These rolls will be played in the game and the program\n"
      << "will tell you what you have won or lost. The Rules are:\n"
      << "A player places a bet of $5.00\n"
      << "All three dice are sixes : player wins $50.\n"
      << "All three dice are the same (but not sixes): player wins $20.\n"
      << "Any two of the dice are the same: player wins $5.00.\n"
      << "None of the dice are the same: player loses $5.00 bet!" << endl << endl << endl;


Notice the only time i use the ";" is on the last line when everything I want to output is done.

Good luck with your program!
Topic archived. No new replies allowed.