Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

C# Programming Help! Cases and other beginner probz

$
0
0

Need to know how to make two keywords for cases, its a basic calc so was wondering how to give the user the option of entering either 1 or add, not sure how to code that into the case, below in case 1 is where i tried. Also im new so if theres any advice, help, or even suggestions to try as a project or sometime of direction would be cool to hear thanks.

bool wantToQuit = false;
            string action = "5 || Quit";
            int currentNumber = 0;
            int number2 = 0;

            Console.WriteLine("Enter A Number To Work With:");
            currentNumber = Convert.ToInt32(Console.ReadLine());

            while (!wantToQuit)
            {
                Console.WriteLine("What would you like to do?");
                Console.WriteLine("0- Clear");
                Console.WriteLine("1- Add");
                Console.WriteLine("2- Subtract");
                Console.WriteLine("3- Divide");
                Console.WriteLine("4- Multiply");
                Console.WriteLine("5- Quit");

                action = Console.ReadLine();

                Console.WriteLine("Enter Another Number To Manipulate The First:");
                number2 = Convert.ToInt32(Console.ReadLine());                            //when it crashes this line appears as an error

                switch (action)
                {
                    case (action == "1" || "Add"):             //how can i make 1 and add keywords for user inputs       
                        currentNumber +=number2; 
                        break;
                    case "2":
                        currentNumber -= number2;
                        break;
                    case "3":
                        currentNumber /= number2;
                        break;
                    case "4":
                        currentNumber *= number2;
                        break;
                    case "5":              //when i type quit, it first asks me to enter the second number
                        wantToQuit = true;
                        break;
                    default:                //any abstract response crashes the program
                        Console.WriteLine("Error");
                        break;

                

Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>