C
C#10mo ago
light

simple calculator

i want to code an simple calculator and i want if i type an anything than number console says enter an number
No description
6 Replies
Pobiega
Pobiega10mo ago
use int.TryParse C# is a strictly typed language, so your code as is doesnt really make any sense int number1 means number1 can only hold int - therefor, your if statement below cant work
light
lightOP10mo ago
i got it string value; int res; Console.WriteLine("enter an number lol"); int number1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter another number"); int number2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("put ,/,-,+"); string symbol = Console.ReadLine(); switch (symbol) { case "": res = number1 * number2; Console.WriteLine(res); break; case "/": res = number1 / number2; Console.WriteLine(res); break; case "+": res = number1 + number2; Console.WriteLine(res); break; case "-": res = number1 - number2; Console.WriteLine(res); break;
} Console.WriteLine("wana continue (y) (n)"); value = Console.ReadLine(); while (value == "y" || value == "Y") ; but how can i like when i say Y it would repeat the code again?
Joschi
Joschi10mo ago
$code
MODiX
MODiX10mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
light
lightOP10mo ago
wait i didnt? mb
Want results from more Discord servers?
Add your server