C# switch case how to calculate -
He is trying to add two numbers simultaneously through the I'am switch number
I have 3 inputs, numbers 1 and number 2. The third input is a method that I want to calculate 1 and 2 (like +
, -
, *
, / < / Code>, etc ...)
The problem now is how can I create "this"? I have tried this way, but it does not work ... Is it possible to make switch case: case%:
???
thanks
string first number; String second number; String method; // Mill number console.light line ("get first number"); FirstNumber = Console.ReadLine (); Console.light line ("get 2 numbers"); SecondNumber = console. Readline (); Console.light line ("method to calculate"); Console.light line ("1: \" * \ ""); Console.light line ("2: \" / \ ""); Console.light line ("3: \" + \ ""); Console.light line ("4: \" - \ ""); Method = Console.ReadLine (); // Convert Into Method New = Convert. ToInt32 (method); Int firstNumberNew = Convert toInt32 (first number); Int secondNumberNew = Convert toInt32 (secondNumber); Switch (method new) {case 1: first numberNew = * secondsNewNew; break; Default: Console. WrightLine ("check the methods."); break; } Console. WrightLine (methodNew);
Of course, you can read in char
and its For a switch-case
:
int c = console Read (); // Read from the console switches (c) {case '/': // work break; Case '%': // Work Break; Case '*': // Work Break; Cases '+': // Work Break; }
Comments
Post a Comment