I'm a beginner for c++ and have some problems here !
currently, i have a text file named "users.txt" and there are a few data stored inside the text file:
simon
1234
123123
john
4321
34343
weejay
8888
7777
dicson
4444
3333
kendy
5555
9998
At first, users need to enter the username and pincode to login. But, when i run the program it will directly said that i've entered invalid pincode or ID although i've entered correctly. May i know how to solve this ??
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std ;
struct users {
string name ;
string pincode ;
int amount ;
};
int main ()
{
cin.sync_with_stdio(0);
cin.tie(0);
string name[10] ;
string pincode [10];
int amount [10];
users obj [10] ;
ifstream infile("users.txt");
for (int i=0; i <10 ; i++)
{
infile >> name [i];
infile >> pincode [i];
infile >> amount [i] ;
}
w:
string username ;
string password;
cout <<"enter username : " << endl ;
cin.ignore();
getline(cin, username);
cout << "enter password : " << endl ;
cin.ignore();
getline(cin, password );
bool islogin = false ;
for (int i=0; i < 10 ; i++)
{
if (password == pincode[i] && username == name[i] )
{
cout << "successfully log in ! " << endl ;
islogin = true ;
break ;
}else
{
islogin = false ;
}
}
if (!islogin)
{
cout << "sorry you have entered invalid pin code or ID " << endl ;
cout << "you want to login again " << endl ;
cout << "1. yes" << endl ;
cout << "2. no" << endl ;
char option ;
cin >> option ;
if (option == '1')
{
system("cls");
fflush(stdin);
goto w ;
}else
{
cout << "thanks for using our system " << endl;
}
}
}