I'm trying to have the program check the user entry in chars against the Password "prog". The user has three tries to get the right Password. However it often gives the answer "right Password" although it doesnt match.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
int tries = 0;
bool valid = false;
bool p, r, o, g;
char userInput;
int characters;
while (tries < 3 && valid == false)
{
Console.WriteLine("Please enter password:");
p = r = o = g = false;
characters = 0;
while (characters < 4)
{
userInput = Console.ReadKey().KeyChar;
if (userInput == 'p' || userInput == 'P') p = true;
else if (userInput == 'r' || userInput == 'R') r = true;
else if (userInput == 'o' || userInput == 'O') o = true;
else if (userInput == 'g' || userInput == 'G') g = true;
characters++;
}
if (p == r == o == g == true)
{
valid = true;
}
tries++;
}
if (valid == true)
{
Console.WriteLine("\nright password");
}
else Console.WriteLine("\nwrong password");
Console.ReadLine();
}
}
}