Can't get the value of two numbers in C# to add after -
so i'm trying ask 2 numbers use after add later , call them console.write()
, doesn't seem work.
first created 3 intengers, int num1 = 0; int num2 = 0; int num3 = 0;
and did this:
console.writeline("what's first number?"); num1 = console.read(); console.writeline("what's second number?"); num2 = console.read(); num3 = num1 + num2; console.writeline(num3);
and reason not working, giving me value of 60+ without me typing second number.
any appreciated , in advance.
console.read()
returns character value, not number entered. plus, returns first character typed in. should using console.readline()
instead.
you can try following:
console.writeline("what's first number?"); int num1 = convert.toint32(console.readline()); console.writeline("what's second number?"); int num2 = convert.toint32(console.readline()); int num3 = num1 + num2; console.writeline(num3);
console.readline()
returns string you'll need convert value int
.
hope helps!
wiki
Comments
Post a Comment