why this program doesn't work ??

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
#include<iostream>
using namespace std;
int main()
{
    char a[80],b[80];
    const char d[]="Hasak";
    const char e[]="nimukaet";
    int c=1;
    a:cout<<"Username: "; cin>>a;
    cout<<"Password: "; cin>>b;
    if(a[5]==d[5] && b[9]==e[9])
    {
                  cout<<"Welcome!"<<endl;
    }
    else
    {
        if(c>=3)
        {
                cout<<"You enter wrong username or password 3 times!"<<endl;
                system("pause");
                return 0;
        }
        cout<<"Wrong username or password!"<<endl<<"Try again"<<endl<<endl;
        c++;
        goto a;
    }
    system("pause");
    return 0;
}
line 11 e[9], but in line 7 e only has 8 elements
Use std::strcmp to compare C strings.
http://www.cplusplus.com/reference/cstring/strcmp/

Or stop using C strings and use std::string instead. std::string can be compared using the == operator.
http://www.cplusplus.com/reference/string/string/
Just use string. Not really much of a reason to use C-style strings in C++. Also, line 9, a:cout<<, why is there a colon there?
was just checking errors with a compiler and missed the idea of that software. but this doesn't work because it makes no sense
if(a[5] == d[5]) means it's true if the 6th element of a and d is the same, you probably want to check the whole word, not just a letter.
Last edited on
Topic archived. No new replies allowed.