Answer to Question #265465 in C++ for Sarang

Question #265465

Define username and password as array variables

In the program, set an initial value for the variables

  • Username: default
  • Password: admin

The user should be able to login using the default credentials

The program should be able to change the default values of the array

If the user tries to login using wrong credentials he will be asked to re-login but after 3 wrong attempts the program will display "You've exceeded the allowable number of tries! Try again later"

If the user successfully logged in, the message "Welcome to my World" should be displayed on screen

if this can done in a user-define function, it would be better but not required for now.


SCREEN LAYOUT / DESIGN

Username: default

Password: admin


Change Username and Password

[Y/N]: Y


(Input new value for UN and PW.)

Username: correct UN

Password: correct PW


Welcome to my World


(If wrong credentials)


Username: wrong UN

Password: wrong PW

(for the 3rd time)


You've exceeded the allowable number of tries! Try again later

1
Expert's answer
2021-11-13T12:41:57-0500
#include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i=0;
 string	Username  ="default"; 
string  Password  ="admin"; 
	while(i<4){
		cout<<"Username:  ";
		string user;
		 
		cin>>user;
		cout<<"Password: ";
		string pass;
		cin>>pass;
		if(user==Username && Password==pass){
			cout<<" Welcome to my World\n";
			break;
		}
		else{
			cout<<"Wrong credentials\n";
			if(i==3){
				cout<<"You've exceeded the allowable number of tries! Try again later\n";
				break;
			}
		}
		i++;
		
	}
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS