mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2025-12-06 05:32:03 +01:00
Fixed logic error in password loop
This commit is contained in:
parent
84f4e5640f
commit
ea406c2372
|
|
@ -10,7 +10,9 @@ while (x < 10)
|
||||||
|
|
||||||
// Looping with the do statement
|
// Looping with the do statement
|
||||||
|
|
||||||
|
string? actualPassword = "Pa$$w0rd";
|
||||||
string? password;
|
string? password;
|
||||||
|
int maximumAttempts = 10;
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|
@ -19,15 +21,16 @@ do
|
||||||
Write("Enter your password: ");
|
Write("Enter your password: ");
|
||||||
password = ReadLine();
|
password = ReadLine();
|
||||||
}
|
}
|
||||||
while ((password != "Pa$$w0rd") & (attempts < 10));
|
while ((password != actualPassword) & (attempts < maximumAttempts));
|
||||||
|
|
||||||
if (attempts < 10)
|
if (password == actualPassword)
|
||||||
{
|
{
|
||||||
WriteLine("Correct!");
|
WriteLine("Correct!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteLine("You have used 10 attempts!");
|
WriteLine("You have used {0} attempts! The password was {1}.",
|
||||||
|
arg0: maximumAttempts, arg1: actualPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looping with the for statement
|
// Looping with the for statement
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ while (x < 10)
|
||||||
|
|
||||||
// Looping with the do statement
|
// Looping with the do statement
|
||||||
|
|
||||||
|
string? actualPassword = "Pa$$w0rd";
|
||||||
string? password;
|
string? password;
|
||||||
|
int maximumAttempts = 10;
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|
@ -19,15 +21,16 @@ do
|
||||||
Write("Enter your password: ");
|
Write("Enter your password: ");
|
||||||
password = ReadLine();
|
password = ReadLine();
|
||||||
}
|
}
|
||||||
while ((password != "Pa$$w0rd") & (attempts < 10));
|
while ((password != actualPassword) & (attempts < maximumAttempts));
|
||||||
|
|
||||||
if (attempts < 10)
|
if (password == actualPassword)
|
||||||
{
|
{
|
||||||
WriteLine("Correct!");
|
WriteLine("Correct!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteLine("You have used 10 attempts!");
|
WriteLine("You have used {0} attempts! The password was {1}.",
|
||||||
|
arg0: maximumAttempts, arg1: actualPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looping with the for statement
|
// Looping with the for statement
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue