-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlayWithIntDoubleAndString.cs
40 lines (37 loc) · 1.45 KB
/
PlayWithIntDoubleAndString.cs
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
32
33
34
35
36
37
38
39
40
// 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;
using System.Threading;
using System.Globalization;
class PlayWithIntDoubleAndString
{
static void Main()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Console.WriteLine("Please choose a type:");
Console.WriteLine("1 --> int");
Console.WriteLine("2 --> double");
Console.WriteLine("3 --> string");
int userChoice = int.Parse(Console.ReadLine());
switch (userChoice)
{
case 1:
Console.Write("Please enter an int: ");
int integerNumber = int.Parse(Console.ReadLine());
Console.WriteLine(integerNumber + 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 input = Console.ReadLine();
Console.WriteLine(input + "" + "*");
break;
default: break;
}
}
}