Answer to Question #265772 in C++ for Sarang

Question #265772

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

(prompt 1)

Username: default

Password: admin


Change Username and Password

[Y/N]: Y

(prompt 2)

Username: correct UN

Password: correct PW


Welcome to my World


(prompt 3)

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-14T09:21:27-0500
#include<iostream>
#include <string.h>
using namespace std;
int main(){
	char username [20] = {"default"};
	char password [20] = {"admin"};
	char pass[20];
	char user[20];
	
	cout<<"Username: default\nPassword: admin\n";
cout<<"Change Username and Password\n[Y/N]: ";
char y ; 
cin>>y;
if(y=='Y'){
	cout<<"Enter username\n";
	cin>>user;
	cout<<"Enter password\n";
	cin>>pass;
	
}


for(int x=0; x<20; x++){
	username[x] = user[x];
	password[x] = pass[x];
}


	int i = 1;
	while(i<=4){
		cout<<"Enter username:  ";
		char entered_user[20];
		cin>>entered_user;
		
		
		
		char entered_password[20];
		cout<<"Enter password:  ";
		cin>>entered_password;
		int res1 = strcmp(username, entered_user);
		int res2 = strcmp(password, entered_password);
		if(res1 ==0 && res2==0 ){
			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