简体   繁体   中英

C# , How to have code wait for user input before moving on to do Math

Hi I am in the process of Learning C#, trying to write a short Console Program that will take a users age and convert it into dog years.

The issue I am having is it doesn't wait for the user input, so it assigns 0 as the value then returns 0 (because 0*7 = 0 ) for dog Age

How do I get the code to stop running until the user enters a value

My code:

Console.WriteLine("what is your age?");
string humanAge = Console.ReadLine();
int dogAge = Convert.ToInt32(humanAge) * 7;

Console.WriteLine(dogAge);

This was an issue with the Code Academy App not the code as mariocatch stated; closing the question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM