+ 1
How much is wrong with this code?
I'm trying to use switch statements to create a basic calculator. I am 1.5 months into learning c# so be gentle when you describe how dumb some of my methods are.
6 Answers
+ 6
Please make the code public or post a link to the code so we can see it.
+ 5
We canât see the code.
+ 4
There's lots of minor errors here.
You forgot a semi-colon on lines: 32, 37, 42, and 47.
You created 2 Strings with the same name. To fix this change line 27 from this:
string yourOperation = ConsoleReadLine();
to this:
yourOperation = Console.ReadLine();
On line 32, remove the extra space between 'num' and '2' so that it reads num2.
On line 29, remove the extra semi-colon after your switch statement.
It should look like this:
switch (yourOperation)
{
Finally, all of your cases should be in quotes because these are strings.
Like this:
case "add":
etc...
same thing with the subtract, multiply and divide case.
After those fixes it works.
+ 2
Link and public, if it is not public the link wonât work.
+ 1
thank you so much. alot of the big ideas makes sense but learning the syntax is a long process
0
Sorry. I just made it public.