I found some basic issues with your code and put my thoughts in the comments below.
String name = Console.ReadLine(); // Shows the cursor without a prompt to the user
System.Console.WriteLine("input name");
System.Console.WriteLine("hello {0}", name);
int hello = Console.Read(); // This line reads the new line character (13) from the above line
System.Console.WriteLine("First number input" + hello); // Displays 13 (new line character if the user doesn't enter any value)
int hello2 = Console.Read();
Console.ReadKey(); // Exits the console as soon as a user press a key
System.Console.WriteLine("Second number input" + hello2); // This is never displays to the user
I thought of re factoring it after showing you all the issues. Here's what I've come up with. Have a look. Since you are trying to build a simple application with user inputs you must think of a flow of user inputs and outputs as well.
int firstNumber;
int secondNumber;
string name = string.Empty;
do
{
Console.Clear();
Console.Write("What is your name?");
name = Console.ReadLine();
} while (string.IsNullOrEmpty(name));
Console.WriteLine("Hello {0}", name);
do
{
// This will happen if the user types something that's not a number
Console.Clear();
Console.WriteLine("Hello {0}", name);
Console.Write("Please enter the first number:");
}
while (!int.TryParse(Console.ReadLine(), out firstNumber));
do
{
// This will happen if the user types something that's not a number
Console.Clear();
Console.WriteLine("Hello {0}", name);
Console.WriteLine("First number is: " + firstNumber);
Console.Write("Please enter the second number:");
}
while (!int.TryParse(Console.ReadLine(), out secondNumber));
Console.WriteLine("Second number is: " + secondNumber);
Console.Read();
Enterkey. As far as I can tell,Console.Read()only reads one character, not including theEnter. Anyone care to explain why he's getting 13 inhello2?