error: expected ; before username1

error: expected ; before username1. what seem the problem?
ps i am a begginer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>

int main()
{
    cout <<"Enter your username. "; 
    string username1;
    cin >> username1;

    cout <<"Enter your password. ";
    string password;
    cin >> password;

    if (username1=hello)
        cout <<" Your username is correct." << endl; // see if username is right

    if (password=1235)
        cout <<" your password is correct" << endl; // see if password is right
    else
        cout <<" Please enter the right password" << endl;

    cout <<" You are logged in sucessfully" << endl;
}
Either include directive

using namespace std;

or place std::prefix before every name from the standard library as for example

std::cin >> username1;

Also do not forget to include header <string>
Also on line 13 hello is undeclared and you probably meant == for comparison instead of = for assignment. I think you meant to surround hello and 1235 with quotes like this: "hello" and "1235"
bold is what I changed. Thsi should work for you now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>
#include <string>
using namespace std;

int main()
{
    cout <<"Enter your username. "; 
    string username1;
    cin >> username1;

    cout <<"Enter your password. ";
    string password;
    cin >> password;

    if (username1=="hello")
        cout <<" Your username is correct." << endl; // see if username is right

    if (password=="1235")
        cout <<" your password is correct" << endl; // see if password is right
    else
        cout <<" Please enter the right password" << endl;

    cout <<" You are logged in sucessfully" << endl;
}
Topic archived. No new replies allowed.