2 Errors with Else Statement

Hello,

I am a beginner to C++ programming. I am having trouble writing a simple if and else statement. The errors that display are:

error: expected primary-expression before "else"

and

error: expected `;' before "else"

Can someone tell me how to solve these errors. Thanks for your help!

- Code Assassin
Show the code the causes the error, please.
Sure.

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
#include <iostream>
#include <fstream>
#include <string>
#include <map>
int main (void)
{

using namespace std;

string user , pass;
map<string , string> mp;
cout<< "Welcome to The Round Table RPG.  1) Open Existing Account  2)Open New Account!"<<endl;
if (2 == true);
{
cout<< "Before we begin You will need to sign up for the Round Table RPG. To do this please enter a username!(No spaces allowed!)"<<endl;
cin >> user;
cout<< "Please enter a password!"<<endl;
cin >> pass;
mp[user]=pass;
if ( (mp.find(user)==mp.end()) || (mp[user]!=pass) ) cout<<"LOGIN FAILED"; else cout<<"LOGIN SUCCESS";
}
else (1 == false)
{
  cout<< "INTRUDER! Leave Now!"<<endl;
}

return 0;
}
if (2 == true);

1) You don't want that ; after the if.
2) This is completely wrong. I suggest you go back to the tutorial and re-read everything because you seem to be getting way ahead of yourself.
Firedraco,

You're right. I think I should go over some things and then try this again. Thanks for your help though.

( By the way I'm a 12 year old.)






- Code Assassin

Last edited on
Topic archived. No new replies allowed.