Advertisement
cuniszkiewicz

SwitchCase1

Dec 4th, 2024
32
0
29 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Switch_case
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int input;
  15.             do
  16.             {
  17.                 Console.Clear();
  18.                 Console.WriteLine("Vending Machine:");
  19.                 Console.WriteLine("1: Coffee");
  20.                 Console.WriteLine("2: Tea");
  21.                 Console.WriteLine("3: Water");
  22.                 Console.WriteLine("4: Juice");
  23.                 Console.WriteLine("5: Exit");
  24.                 Console.Write("Choose a drink (1-5): ");
  25.                 input = int.Parse(Console.ReadLine());
  26.  
  27.                 switch (input)
  28.                 {
  29.                     case 1:
  30.                         Console.WriteLine("Here's your coffee!");
  31.                         break;
  32.                     case 2:
  33.                         Console.WriteLine("Here's your tea!");
  34.                         break;
  35.                     case 3:
  36.                         Console.WriteLine("Here's your water!");
  37.                         break;
  38.                     case 4:
  39.                         Console.WriteLine("Here's your juice!");
  40.                         break;
  41.                     case 5:
  42.                         Console.WriteLine("Thank you! Bye bye!");
  43.                         break;
  44.                     default:
  45.                         Console.WriteLine("Wrong choice! Try again!");
  46.                         break;
  47.                 }
  48.  
  49.  
  50.                 /*
  51.                 if (input == 1)
  52.                     Console.WriteLine("Here's your coffee!");
  53.                 if (input == 2)
  54.                     Console.WriteLine("Here's your tea!");
  55.                 if (input == 3)
  56.                     Console.WriteLine("Here's your water!");
  57.                 if (input == 4)
  58.                     Console.WriteLine("Here's your juice!");
  59.                 if (input == 5)
  60.                     Console.WriteLine("Thank you! Bye bye!");
  61.                 if (input != 1 && input != 2 && input != 3 && input != 4 && input != 5)
  62.                     Console.WriteLine("Wrong choice! Try again!");
  63.                 */
  64.                 Console.ReadKey();
  65.  
  66.             } while (input != 5);
  67.         }
  68.     }
  69. }
  70. /*
  71. Objective:
  72. Create a program that acts as a simple calculator.
  73. The program should allow the user to choose a mathematical
  74. operation from a menu, input two numbers, and then display the result.
  75. The selection of operations should be handled using a switch-case statement.
  76.  
  77. Requirements:
  78. Menu of Operations:
  79.  
  80. 1: Addition (+)
  81. 2: Subtraction (-)
  82. 3: Multiplication (*)
  83. 4: Division (/)
  84. 5: Exit
  85. Input:
  86.  
  87. The user selects an operation from the menu by entering a number (1-5).
  88. The program then prompts the user to input two numbers for the calculation.
  89. Calculation:
  90.  
  91. Perform the chosen operation on the two numbers.
  92. For division, ensure that the second number is not zero. If zero is entered,
  93. display an error message.
  94. Exit:
  95.  
  96. The program should loop until the user selects "5: Exit".
  97.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement