Write a C# Sharp program that takes user id and password as input (type string). After 3 wrong attempts, user will be re

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a C# Sharp program that takes user id and password as input (type string). After 3 wrong attempts, user will be re

Post by answerhappygod »

Write a C# Sharp program that takes user id and password as
input (type string). After 3 wrong attempts, user will be rejected.
C# Sharp Code: using System; public class Exercise3 { public static
void Main() { string username, password; int ctr = 0,dd=0;
Console.Write("\n\nCheck username and password :\n");
Console.Write("N.B. : Defaule username and password is : username
and password\n");
Console.Write("---------------------------------\n"); do {
Console.Write("Input a username: "); username = Console.ReadLine();
Console.Write("Input a password: "); password = Console.ReadLine();
if( username == "username" && password == "password" ) {
dd=1; ctr=3; } else { dd=0; ctr++; } } while (( username !=
"username" || password != "password" ) && (ctr != 3)); if
(dd == 0) { Console.Write("\nLogin attemp more than three times.
Try later!\n\n"); } 6 | P a g e Loops in C# Hands-on Ms. Rosita
Glover IST51/IST551 else if(dd==1) { Console.Write(
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply