C
C#4w ago
Jexs

✅ Does it take both types?

in this code: ’’’cs while (true) { Console.Clear(); Console.WriteLine("===== Console Calculator ====="); Console.WriteLine("1. Addition (+)"); Console.WriteLine("2. Subtraction (-)"); Console.WriteLine("3. Multiplication (*)"); Console.WriteLine("4. Division (/)"); Console.WriteLine("5. Exit"); Console.Write("Select an option (1-5): "); string choice = Console.ReadLine(); if (choice == "5") { Console.WriteLine("Exiting... Goodbye!"); break; } Console.Write("Enter first number: "); if (!double.TryParse(Console.ReadLine(), out double num1)) { Console.WriteLine("Invalid input! Press any key to try again."); Console.ReadKey(); continue; } ’’’ the method takes in both normal numbers and decimal numbers ?
8 Replies
Yawnder
Yawnder4w ago
Which method? This is just free-form code. Also, $code
MODiX
MODiX4w 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/
Ꜳåąɐȁặⱥᴀᴬ
i guess he means TryParse? anyway i would pass CultureInfo.InvariantCulture to TryParse just in case i don't know if your decimal number is with , or with .
FusedQyou
FusedQyou4w ago
Yes it does, but most importantly $tias
FusedQyou
FusedQyou4w ago
If you tried your code with both inputs you'd have a faster answer than anybody here would give, and it's good practice
Jexs
JexsOP4w ago
Sorry idk why I called it a method I ment line (!double.TryParse(Console.ReadLine(), out double num1)) idk why I can’t get the standard layout to show on discord using ’’’ cs ’’’ Oh okay @FusedQyou yea!
jcotton42
jcotton424w ago
It’s `, not ‘.

Did you find this page helpful?