Question: please help me with my logic... so I am making a user login . . . and it works... however... lets say i login and
please help me with my logic... so I am making a user login and it works... however... lets say i login and then close the program and a new user tries to login and they dont exist in the txt file, the program just kind of bypasses the fact they have to register and logs in the last person who was logged in
i want some kind of logic that only logs in the user IF they exist... and if they dont then they have to register before they continue, but i also want if they do login for it to continue to the body; my mind just cant wrap around the logic
#include
#include
#include
#include
using namespace std;
class User
protected:
char username;
char password;
public:
const char getName const
return username;
void Register
ofstream fslogintxt ios::app;
cout Enter username: ;
cin username;
cout Enter password: ;
cin password;
fs endl username password;
cout "User registered successfully" endl endl;
fsclose;
void loginchar un char pw
int k ;
ifstream fslogintxt;
while fseof
fs username password;
if strcmpun thisusername && strcmppw thispassword
cout Login Sucessful" endl endl;
k ;
else
k ;
if k
cout User does not exist. Please Register.
;
fsclose;
;
#include "User.cpp
int main
User l;
bool loggedIn false;
while loggedIn
char username password;
int ch;
cout Welcome to SMS ;
cout
Login
Create an Account" endl endl;
cout Enter choice: ;
cin ch;
cout endl;
switch ch
case :
cout Username : ; cin username;
cout Password : ; cin password;
lloginusername password;
loggedIn true;
break;
case :
lRegister;
loggedIn false;
break;
default:
std::cout "Invalid choice. Please try again.
;
body of the program
cout "Welcome lgetName You are now logged in Continue with the program...
;
I think it has something to do in main, but it could be in the login function... please try the program out and you will see what I mean with the logic
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
