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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
using System; class PlusOneOrAsterix { static void Main() { Console.WriteLine("Type a string or a number: "); string inputVar = Console.ReadLine(); int iVar; double dVar; bool itSint; bool itSdouble; if (itSint = int.TryParse(inputVar, out iVar)) { iVar++; Console.WriteLine(iVar); } else if (itSdouble = double.TryParse(inputVar, out dVar)) { dVar++; Console.WriteLine(dVar); } else { Console.WriteLine(inputVar + "*"); } } } |