C
C#3mo 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
Pobiega3mo 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
light3mo 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
Joschi3mo ago
$code
MODiX
MODiX3mo 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 User3mo ago
Message Not Public
Sign In & Join Server To View
light
light3mo ago
wait i didnt? mb
Want results from more Discord servers?
Add your server
More Posts
Pagination with C# (DotNet) + Angular problem.Hey gyus first of all thanks for anyone who gonna help me 🙂 I tried to implement pagination with c#✅ Anyone recommend a book, or online course?Hey guys, anyone have a book or video course they'd recommend for learning asp.net mvc and blazor? I✅ Need help with recursive solution on vjudge Homer Simpson UVA - 10465 problem with CI am trying to solve https://vjudge.net/problem/UVA-10465 or at least get "Time exceeded" (3000ms) iOpen Closed Principle confusionIn the case of some logic involving a class. Eg. There maybe an Account class and we calculate the i✅ How do I replace each character with a character that corresponds to the standard English layout?There is a string with the characters "ЙЦУКЕН". It corresponds to the "QWERTY" string of the standar✅ Using Options pattern in MAUII'm trying to squeeze some Options pattern config into my MAUI app, in `MauiProgram`, like this: ```✅ JWT questionI can generate a token fine. However when I use the token, it refuses to work. If anyone is kind enoPossible to F12 into C# source?VS 2022 latest version. When I F12 onto something like `.FirstOrDefault()` it just tells me a summaThread.sleep in a constructorSince you can't await in a constructor, I'm calling an async method and just sleeping the thread forEbay's new "RESTFUL" api's seem to have done away with seller JSON responsesIt looks like I can't just query my own ebay listings (auctions, buynows). They have some weird sche