Trouble with If Else

Beginner with C++ and I keep getting a expected primary-expression before "else" error. I thought it was because I added ; after the if statement bu then I got an error for expecting a ; before the else, so very confused. The if else I'm having trouble with is the one bolded. Here is the section of the code I'm trying to fix currently, any help would be much appreciated.

do //Pick up sticks
{
cout<<"There are "<<sticks<<"left on the pile";
{
if (user_die > computer_die)
cout<<"It is your turn "<<name<<"\n";
cout<<"How many sticks would you like to take? 1-4.\n";
cin>>take;
{
if (take>=1 && take<=4);
(sticks - take);
cout<<"There are "<<sticks<<" left on the pile\n\n";
else
cout<<"Sorry you tried to take an invalid number of sticks you lose your turn\n\n";

}
system("PAUSE");

cout<<"Computer's turn\n";
take = rand ()%4 + 1;
sticks - take
cout<<"Computer is takeing "<<take<<" Sticks\n";
system("PAUSE");
{
if sticks<0
cout<<"Computer tried to take more sticks than there are, Computer loses its turn";
sticks + take;
else
cout<<"There are now "<<sticks<<" left on the pile";
}
system("PAUSE");

else
cout<<"Computer's turn\n";
take = rand ()%4 + 1;
sticks - take
cout<<"Computer is takeing "<<take<<" Sticks\n";
system("PAUSE");
if sticks<0
cout<<"Computer tried to take more sticks than there are, Computer loses its turn"
sticks + take
else
cout<<"There are now "<<sticks<<" left on the pile"
system("PAUSE");

cout<<"It is your turn "<<name"\n";
cout<<"How many sticks would you like to take? 1-4.\n";
cin>>take
if take>=1 && take<=4
sticks - take
cout<<"There are "<<sticks<<" left on the pile\n\n";
else
cout<<"Sorry you tried to take an invalid number of sticks you lose your turn\n\n";
}
system("PAUSE");

}while(sticks>0);
please use code tags my eyes will thank you.
http://www.cplusplus.com/articles/z13hAqkS/

I think you wan't this
1
2
3
4
5
6
7
if (take>=1 && take<=4)
{
     sticks = sticks - take;
     cout<<"There are "<<sticks<<" left on the pile\n\n";
}
else
     cout<<"Sorry you tried to take an invalid number of sticks you lose your turn\n\n";


if you wan't an if statement to execute more than one statement you need to use {}
and you do not use a ; at the end of an if condition if (take>=1 && take<=4);
Last edited on
Topic archived. No new replies allowed.