Difference between revisions of "2022 - You cause an exception if you enter a card number out of the range 1-5"
(→Issue) |
(→What you need to do) |
||
Line 20: | Line 20: | ||
=What you need to do= | =What you need to do= | ||
− | * this method should test if value is | + | * this method should test if value is < 1 |
− | * this method should test if values is | + | * this method should test if values is > 5 |
* this method should still not accept non integer values | * this method should still not accept non integer values |
Revision as of 12:18, 18 November 2021
Issue
When you are asked to enter a card number you can enter invalid values (ie not 1 to 5). The GetCardChoice method of the BreakThrough class is what gets the value from the user, this is the code below:
private int GetCardChoice()
{
string Choice;
int Value;
do
{
Console.Write("Enter a number between 1 and 5 to specify card to use:> ");
Choice = Console.ReadLine();
}
while (!int.TryParse(Choice, out Value));
return Value;
}
This method currently will ignore any non integer values entered.
What you need to do
- this method should test if value is < 1
- this method should test if values is > 5
- this method should still not accept non integer values