Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 9. Play with Int, Double and String
- //Write a program that, depending on the userβs choice, inputs an int, double or string variable. If the variable is int or double, the program increases it by one. If the variable is a string, the program appends "*" at the end. Print the result at the console. Use switch statement.
- using System;
- class PlayIntDoubleString
- {
- static void Main()
- {
- Console.WriteLine("Please, choose a type:");
- Console.WriteLine("1--> int");
- Console.WriteLine("2--> double");
- Console.WriteLine("3--> string");
- Console.Write("choose:");
- int choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.Write("Please, enter integer number:");
- int number = int.Parse(Console.ReadLine());
- Console.WriteLine(number+1);
- break;
- case 2:
- Console.Write("Please,enter a double:");
- double doubleNumber = double.Parse(Console.ReadLine());
- Console.WriteLine(doubleNumber+1);
- break;
- case 3:
- Console.Write("Please, enter a string:");
- string myString = Console.ReadLine();
- Console.WriteLine(myString + "*");
- break;
- default:
- Console.WriteLine("Some , Error");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement