Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // Write a program that, depending on the user’s choice, inputs int, double or string variable.
- // If the variable is int or double, the program increases it by 1. If the variable is a string,
- // the program appends "*" at the end. Print the result at the console. Use switch statement.
- namespace Chap_5_Exc_08
- {
- class Program
- {
- static void Main()
- {
- Console.WriteLine("Please enter 1 for int 2 for double and 3 for string :");
- int choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.WriteLine("Enter a whole number"); break;
- case 2:
- Console.WriteLine("Enter floating point number"); break;
- case 3:
- Console.WriteLine("Enter a string"); break;
- default:
- Console.WriteLine("Ivalid choice"); break;
- }
- if (choice == 1)
- {
- int choiceOne = int.Parse(Console.ReadLine());
- choiceOne += 1;
- Console.WriteLine(choiceOne);
- }
- else if (choice == 2)
- {
- double choiceTwo = double.Parse(Console.ReadLine());
- choiceTwo += 1;
- Console.WriteLine(choiceTwo);
- }
- else
- {
- string choiceThree = Console.ReadLine();
- Console.WriteLine(choiceThree + "*");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement