simple calculator
i want to code an simple calculator and i want if i type an anything than number console says enter an number
6 Replies
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 worki 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?
} 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?
$code
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•10mo ago
Message Not Public
Sign In & Join Server To View
wait i didnt?
mb