Added item for page 116

This commit is contained in:
Mark J Price 2023-04-06 08:13:30 +01:00
parent 782f1f7074
commit 84f4e5640f
2 changed files with 40 additions and 2 deletions

View file

@ -2,7 +2,7 @@
If you find any mistakes in the seventh edition, *C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals*, or if you have suggestions for improvements, then please [raise an issue in this repository](https://github.com/markjprice/cs11dotnet7/issues) or email me at markjprice (at) gmail.com.
[**Errata** (37 items)](errata.md): Typos, tool user interface changes, or mistakes in code that would cause a compilation error that prevents a successful build.
[**Errata** (38 items)](errata.md): Typos, tool user interface changes, or mistakes in code that would cause a compilation error that prevents a successful build.
[**Improvements** (26 items)](improvements.md): Changes to text or code that would improve the content. These are optional.

View file

@ -1,4 +1,4 @@
**Errata** (37 items)
**Errata** (38 items)
If you find any mistakes, then please [raise an issue in this repository](https://github.com/markjprice/cs11dotnet7/issues) or email me at markjprice (at) gmail.com.
@ -14,6 +14,7 @@ If you find any mistakes, then please [raise an issue in this repository](https:
- [Page 85 - Getting text input from the user](#page-85---getting-text-input-from-the-user)
- [Page 86 - Getting text input from the user](#page-86---getting-text-input-from-the-user)
- [Page 114 - Simplifying switch statements with switch expressions](#page-114---simplifying-switch-statements-with-switch-expressions)
- [Page 116 - Looping with the do statement](#page-116---looping-with-the-do-statement)
- [Page 156 - Calculating factorials with recursion](#page-156---calculating-factorials-with-recursion)
- [Page 166 - Setting a breakpoint and starting debugging - Using Visual Studio 2022](#page-166---setting-a-breakpoint-and-starting-debugging---using-visual-studio-2022)
- [Page 178 - Reviewing project packages](#page-178---reviewing-project-packages)
@ -184,6 +185,43 @@ Cat fourLeggedCat when fourLeggedCat.Legs == 4
=> $"The cat named {fourLeggedCat.Name} has four legs.",
```
# Page 116 - Looping with the do statement
> Thanks to Norbert Duenki who raised this issue by email on 4 April 2023.
In Step 3, I wrote, "As an optional challenge, add statements so that the user can only make ten attempts before
an error message is displayed."
In my code solution in GitHub, I made a mistake in my logic so that if the user entered the correct password on their tenth attempt, it output the error message.
I have updated the logic to fix this issue, as well as to use variables to store the actual password and the maximum number of attempts, as shown in the following code:
```cs
// Looping with the do statement
string? actualPassword = "Pa$$w0rd";
string? password;
int maximumAttempts = 10;
int attempts = 0;
do
{
attempts++;
Write("Enter your password: ");
password = ReadLine();
}
while ((password != actualPassword) & (attempts < maximumAttempts));
if (password == actualPassword)
{
WriteLine("Correct!");
}
else
{
WriteLine("You have used {0} attempts! The password was {1}.",
arg0: maximumAttempts, arg1: actualPassword);
}
```
# Page 156 - Calculating factorials with recursion
> Thanks to [Ricky](https://github.com/r1c5) for raising this [issue on 29 January 2023](https://github.com/markjprice/cs11dotnet7/issues/21).