errors using default for switch statement c#

closed account (9j26pfjN)
im trying to use default at the end of my switch statement and i keep getting errors! im getting frustrated please help

im very new to programming and its quite confusing lol

case "d":

Console.WriteLine("Please enter your option here:");
Console.WriteLine("First number");
double firstNum = Int32.Parse(Console.ReadLine());
Console.WriteLine("Second number:");
double secondNum = Int32.Parse(Console.ReadLine());
double sum = firstNum / secondNum;
Console.WriteLine("Result:" + sum);
Console.WriteLine("\n");
Console.ReadKey();
break;
}
default:

else if (number == 2)

{

Console.WriteLine("Exiting the code");
Console.WriteLine("Please press any key to exit");
Console.ReadLine();
break;
}

else
{

Console.WriteLine("Wrong selection");
Console.WriteLine("Please press any key to go to the main menu");
Console.ReadLine();
Active
Error CS1002 ; expected ConsoleApp50 69 Active
Error CS1513 } expected ConsoleApp50 69 Active
Error CS1513 } expected ConsoleApp50 98 Active
Hi! While I wish you luck, this is a C++ forum, not a C# one, and despite being named similarly the two languages are very different.

That said, you might want to reread how to write a switch statement, since I'm pretty sure that default: else if isn't valid. It also looks a little bit like just below your first break statement, you actually leave your switch statement, but we wouldn't be able to tell without seeing more code.


-Albatross
Last edited on
Edit: This is 100% a you-know-what profile that we didn't catch. All of the user's posts are verbatim copies from other websites, and the user profile here has links in it.

This post is verbatim also posted https://stackoverflow.com/questions/57351975/errors-using-default-for-switch-statement-c-sharp with a profile that doesn't match this in any way.
Last edited on
Ah, damn it. Thanks for the heads-up.

-Albatross
Topic archived. No new replies allowed.