Expected primary-expression before "else"

Expected primary-expression before "else"
That is the error I get in both "else" and "else if".
What is wrong in this code.( I searched all around and tried "everything" but found no solution.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  int Answer1,Yes,No,yes,no;
  cin >>Answer1;
  if (Answer1=yes)(Answer1=Yes)
  ;
  {
  cout << "\nStuff here!\n";
  }
  else if (Answer1=no)(Answer1=No)
  ;
  {
  cout << "\nMore stuff here!\n";
  }
  else
  ;
  {
  cout << "\nEven more stuff here!\n";
  return 18; //Note:Line 18 is in my original code, line 1 here.
  }
Last edited on
Why are there ;'s after your if statements?
Without those There comes errors: expected `;' before '{' token and still the same as before.
Last edited on
What are you trying to compare in your if statement?
It`s just a part of and text based adventure. xD
A dialogue in it.

Edit: It supposed to work like "Do you want this?" if you say yes, you get it. If no you don`t. If neither you will get question like : "Are you sure?" and it begins in start.
Last edited on
Well:

1, you aren't comparing anything. You're assigning Answer1 to yes and then assigning Answer1 to Yes.

2, your if statements should be something like
1
2
3
4
5
if (Answer1 == yes || Answer1== Yes)
{
     cout << "stuff here" << endl;
}
else if....etc
Thank you, That worked.
Last edited on
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
int main ()
{
  cout << "Stuff";
  cout << "\n\nStuff\n\n";  
  int Name;
  cin >> Name;
  cout << "\nStuff\n";
  cout << "<Press any key to do stuff.>\n\n";
  system("pause>null");
  cout << "Stuff.\n";
  cout << "Stuff.\n";
  int Answer1,Yes,No,yes,no; 
  cin >>Answer1;
  if (Answer1==yes || Answer1==Yes) 
  
  {
  cout << "\nStuff\n";
  }
  else if (Answer1==no || Answer1==No)
  
  {
  cout << "\nStuff\n";
  }
  else
  ;
  {
  cout << "\nStuff\n";
  return 18;
  }
  
  
  
  system("pause>nul");
}


Theres the whole "int main". Now the problem is that before that I put there that "if,if else,else"-thing, when I pressed any key it just went on. Now (after adding that code from int Answer1, etc. to return 18;} it just closes the program, with system("pause>null") or without.
Last edited on
else
;
{
cout << "\nStuff\n";
return 18;
}


Get rid of the ; after the else.

When main returns something (anything) it exits the function, thus closing the program.
Last edited on
Doesn`t help. It still just closes the program.
Because you're returning something in Main, lol...

when I said to get rid of the ;, I was just saying that because I saw it there.

You can't return something in main without the program closing.
Oh, sorry about not reading your previous comment with care. Anyways I think the problem is that the line "cin >>Answer1;" isn`t working properly, because I tried it without the "return", and program ignored line "cin >>Answer1;" and just shew me the line "else". I wasn`t able to do the Aswer1, program just skipped it.
Last edited on
Well, you never initialized your variables to anything.

So they have random bit patters in them right now, and I doubt those random bit patters match, so your if statement is always returning false causing you to always go to the else.
Sorry for bothering you so much but how about this.
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
int main ()
{
  cout << "Stuff";
  cout << "\n\nStuff\n\n";  
  int Name;
  cin >> Name;
  cout << "\nStuff\n";
  cout << "<Press any key to do stuff.>\n\n";
  system("pause>null");
  cout << "Stuff.\n";
  cout << "Stuff.\n";
  int Answer1,Yes=1,No=2,yes=1,no=2; 
  cin >>Answer1;
  if (Answer1==1)
  
  {
  cout << "\nStuff\n";
  }
  else if (Answer1==2)
  
  {
  cout << "\nStuff\n";
  }
  else
  {
  cout << "\nStuff\n";
  }
  
  
  
  system("pause>nul");
}


What is wrong in this version?
Well, what are you putting into Answer1 when you use cin?
Yes/No/yes/no, however it always gets the "else" statement.(How do I make it work like this)
Now only 1/2 works.
Last edited on
because Yes/No/yes/no are not ints. all your variables are of type int. You should put them as character arrays or strings if you want them to store info like that.
Well thank you for all your help. I think I`ll just use comments like "Press 1 to do that and this, press 2 to do this and that".
Topic archived. No new replies allowed.