Introduction
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
using System; public class Stringexercise { public static void Main() { string username, password; int ctr = 0; do { Console.Write("Input a username: "); username = Console.ReadLine(); Console.Write("Input a password: "); password = Console.ReadLine(); if (username != "abcd" || password != "1234") ctr++; else ctr = 1; } while ((username != "admin" || password != "123456") && (ctr != 3)); if (ctr == 3) Console.WriteLine("\nLogin attemp three or more times. Try later!"); else Console.WriteLine("\nThe password entered successfully!"); Console.ReadLine(); } }
Hard coded username and password is not good way to implement this. Hope you know it.