+ 1

What is wrong on my code? C# Add two number

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int x ; int y ; x= Console.Read(); y= Console.Read(); Console.WriteLine(x-y); } } }

27th Feb 2022, 11:54 AM
Sayem chy
Sayem chy - avatar
3 Answers
+ 3
Sayem chy You wrote in question Add two numbers but you are doing subtraction. Why? + means addition - means subtraction * multiplication / division
27th Feb 2022, 1:36 PM
AÍąJ
AÍąJ - avatar
+ 2
When you read from console, strings will be returned. You declared x and y as int, hence you need to cast the input to integer before assigning it to x and y. Also "add" means +, not –.
27th Feb 2022, 12:09 PM
Lisa
Lisa - avatar