I have this C# and it is a login program. It works like this:
The program asks you to enter specific TAG and if you get it wrong you have to put in a password to find your tag.
If enter right password you enter the team. If you don’t get the password right you have to restart program (this is the problem).
And if you get the password right and the team right you get your tag and restart program.
If you enter your team wrong you also have to restart program.
But instead of reopening the program I want so I press a button and it will print out the same program again.
Here is the code
using System;
namespace GOVERMENTPROGRAM
{
internal class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WindowWidth = 70;
Console.WriteLine("WELCOME TO THE A.A.A.R GOVERMENT (Sniper) PROGRAM TO ACCESS INFORMATIONnPLEASE ENTER YOUR ACCOUNT INFORMATION");
Console.Write("TAG:");
Console.ForegroundColor = ConsoleColor.Blue;
String TAG = (Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Green;
if (TAG == "A.A.A_ter5"){
Console.WriteLine("Welcome Sniper #5");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("MISSION OF THE DAY:");
Console.WriteLine("A new cocaine drug dealer is trending in the city");
Console.WriteLine("Your job is too assasinate his team and call our organization");
}
else {
Console.WriteLine("That Does Not exist");
Console.Write("Enter Organization password to reveal TAGSnPASSWORD:");
}
Console.ForegroundColor = ConsoleColor.Blue;
String password = (Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Green;
if (password == "231234TER"){
Console.Write("TEAM(IN XXX):");
Console.ForegroundColor = ConsoleColor.Blue;
String TEAM = (Console.ReadLine());
if (TEAM == "SNIPER") {
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("A.A.A_ter1nA.A.A_ter2");
Console.WriteLine("A.A.A_ter3nA.A.A_ter4");
Console.WriteLine("A.A.A_ter5");
Console.WriteLine("Please close program to restart LOGIN");
}
else{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Wrong, software login is built for specific team and you are not on that team");
Console.WriteLine("Please Enter TOR to restart LOGIN");
Console.ForegroundColor = ConsoleColor.Yellow;
String TOR = (Console.ReadLine());
while (TOR == "TOR"){
}
}
}
else {
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("WRONG");
Console.WriteLine("Please Enter TER to restart LOGIN");
}
String TER = (Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Yellow;
while (TER == "TER"){
}
Console.ReadKey();
}
}
}
Please someone tell me how to achieve this
ammar ahmed2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
You can use a while loop:
Example:
bool state = true;
while (state)
{
// Your logic
state = false; // To drop out of the loop (if needed)
}
Example how I would’ve solved it (even though I had problems understanding what you wrote, sorry to say that but your requirements need to be more clear):
namespace GOVERMENTPROGRAM
{
internal class Program
{
static void Main()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WindowWidth = 70;
Console.WriteLine("WELCOME TO THE A.A.A.R GOVERMENT (Sniper) PROGRAM TO ACCESS INFORMATIONnPLEASE ENTER YOUR ACCOUNT INFORMATION");
Lore();
}
static void Lore()
{
bool state = true;
while (state)
{
Console.Write("TAG:");
Console.ForegroundColor = ConsoleColor.Blue;
string TAG = (Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Green;
if (TAG == "A.A.A_ter5")
{
Console.WriteLine("Welcome Sniper #5");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("MISSION OF THE DAY:");
Console.WriteLine("A new cocaine drug dealer is trending in the city");
Console.WriteLine("Your job is too assasinate his team and call our organization");
}
else
{
Console.WriteLine("That Does Not exist");
state = false;
}
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("Enter Organization password to reveal TAGSnPASSWORD:");
string password = (Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Green;
if (password == "231234TER")
{
Console.Write("TEAM(IN XXX):");
Console.ForegroundColor = ConsoleColor.Blue;
string TEAM = (Console.ReadLine());
if (TEAM == "SNIPER")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("A.A.A_ter1nA.A.A_ter2");
Console.WriteLine("A.A.A_ter3nA.A.A_ter4");
Console.WriteLine("A.A.A_ter5");
Console.WriteLine("Please close program to restart LOGIN");
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Wrong, software login is built for specific team and you are not on that team");
Console.WriteLine("Please Enter TOR to restart LOGIN");
Console.ForegroundColor = ConsoleColor.Yellow;
string TOR = Console.ReadLine();
state = false;
}
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("WRONG");
Console.WriteLine("Please Enter TER to restart LOGIN");
Console.ForegroundColor = ConsoleColor.Yellow;
string TER = (Console.ReadLine());
state = false;
}
}
Console.ReadKey();
Console.Clear();
Reset();
}
static void Reset()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("WELCOME TO THE A.A.A.R GOVERMENT (Sniper) PROGRAM TO ACCESS INFORMATIONnPLEASE ENTER YOUR ACCOUNT INFORMATION");
Lore();
}
}
}
Everything should work except the format, but that was not the question. I believe that there are many tutorials for formatting console output and that they can be found all over the net.
One major thing you should learn is to start using separate methods. I don’t know if you already used separate methods before but they can be really important, especially when it comes to code readability!
Don’t forget that there are more ways to achieve this. You could also use for(;;). Both will do the same thing when checking in CIL.
poisonousheartz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.