0
When the code is run, If num1 = 10 and num2 = 5,the result is giving me 105 instead of 15, how can i fix it to get 15 as result.
using System; namespace Project { class MyClass { public static void Main(string[] args) { int num1; int num2; Console.WriteLine("This calculator would be used to minus two numbers"); Console.WriteLine("Input your first number"); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Input the second number"); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The result is..." + num1 + num2); Console.ReadKey(); } } }
3 Antworten
+ 2
Don't use + operator, it will do string concatenation because one of the operands were a string. In this case the string "The result is..." to the left of the two numbers.
Console.WriteLine("The result is {0}", num1 + num2);
+ 2
If you add a string and a number the number converts automatically to a string. You could add these two numbers before printing them.
+ 1
Add () and put num1+num2 inside them