So, I wrote this code for a school physics project. It's really basic, but I'm new to C# so I think its fine. This isn't a huge issue, but I do want a fix for it for quality. I had my dad run it through a stress test and it broke the program completely when he added a space before the input number, the program was looping the else statement. Whenever he pressed enter to move on from the else statement, it would go right back to it, not even writing the content. I skipped over the if statements because I think personally they aren't relevant to the issue. But they are your standard if statements. I have also racked my brain for a solution, but I can't really think of one. I feel like this situation is really unique, so I couldn't really find anything online. Thank you for your time! If more code is needed please let me know.
///Establishes content
start:
Console.WriteLine(@"What would you like to learn about? Type the number next to the topic:
What is a circuit? (1)
Voltage (2)
Current (3)
Resistance (4)
Ohm's Law (5)
Power (6)
Series Circuit Rules and Diagrams (7)
Parallel Circuit Rules and Diagrams (8)");
///Takes input from user
Console.Write("Please input here: ");
string ReqNum = Console.ReadLine();
///Else statement loops
else
{
Console.Clear();
Console.WriteLine("You entered an incorrect statement or the program has glitched. Please input a number from 1-8 else the program will not work.");
Console.Read();
goto start;
}
Aucun commentaire:
Enregistrer un commentaire