Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class UserChoiceToEnterIntOrDoubleOrStringAndDoActions
- {
- static void Main()
- {
- //Write a program that, depending on the user's choice inputs int, double or string variable. If the variable is integer or double, increases it with 1. If the variable is string, appends "*" at its end. The program must show the value of that variable as a console output. Use switch statement.
- Console.Write("Please choose what type of variable you want to enter.\n 1 : Integer\n 2 : Double\n 3 : String\nEnter your choice 1, 2 or 3 here: ");
- byte choice = byte.Parse(Console.ReadLine());
- Console.Write("Please enter your variable:");
- string userinput = Console.ReadLine();
- switch (choice)
- {
- case 1:
- {
- int integerVar = int.Parse(userinput);
- integerVar += 1;
- Console.WriteLine("The increased value of your number is: {0}", integerVar);
- }
- break;
- case 2:
- {
- double doubleVar = double.Parse(userinput);
- doubleVar += 1;
- Console.WriteLine("The increased value of your number is: {0}", doubleVar);
- }
- break;
- case 3:
- userinput += "*";
- Console.WriteLine("The new value of your string is: {0}", userinput);
- break;
- default: Console.WriteLine("Wrong input!");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement