program not continuing
i have coded the below code but when i press one of the keys i have putted in the menu the program simply closes
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int main()
{
ofstream pass;
ofstream username;
ifstream admin1;
ifstream pass1;
ifstream username1;
char ad, ps, repeat, menu;
string admin, password, user;
string psi;
string admini;
string useri;
pass.open("pass.txt");
username.open("user.txt");
admin1.open("admin.txt");
pass1.open("pass.txt");
username1.open("user.txt");
do{
cout <<"select one of the following options:\n";
cout <<"R register\n";
cout <<"L login\n";
cout <<"ESC exit\n";
menu = _getch();
if ( menu == 82 ){
cout <<"\nenter the admin password:";
ad = _getch();
while(ad != 13){
admin.push_back(ad);
cout << '*';
ad = _getch();
}
if (admin1.is_open()){
while (!admin1.eof()){
getline(admin1,admini);
}
admin1.close();
}
if (admin == admini){
cout << "\nenter your username:";
cin >> user;
cout << "enter your password:";
ps = _getch();
while(ps != 13){
password.push_back(ps);
cout << '*';
ps = _getch();
}
if (username.is_open()){
username << user << endl;
username.close();
}
if (pass.is_open()){
pass << password << endl;
pass.close();
}
cout << "\nto return to the menu press BACKSPACE\n";
repeat = _getch();
}
}
if (menu == 76){
cout << "\nenter your usermame:";
cin >> user;
if (username1.is_open()){
while(!username1.eof()){
getline(username1,useri);
}
username1.close();
}
cout << "enter your password:";
cin >> password;
if (pass1.is_open()){
while(!pass1.eof()){
getline(pass1,psi);
}
pass1.close();
}
if (user==useri && password==psi){
cout << "\nyour data is correct!";
/* inserir função para continuar o programa*/
}
else {
cout << "\nyour data is incorrect. press BACKSPACE to return to the menu\n";
repeat = _getch();
}
}
if (menu == 27){
return 0;
}
}
while(repeat == 8);
}
|
You shall not use _getch. First of all it is a non-standard function. Secondly it does not extract a symbol from the keyboard buffer.
Last edited on
what do you meen with:
it does not extract a symbol from the keyboard buffer. |
Topic archived. No new replies allowed.