Write a program using a switch statement. that asks the user to enter an integer. If the user enters '1', print "Only one?". If the user enters '100', print "100? That's a lot!". If the user enters something other than these two numbers, print "Input not recognized.".
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SwitchStmt
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter an Integer");
int value = 0;
string option = Console.ReadLine();
Int32.TryParse(option, out value);
switch (value)
{
case 1:
Console.WriteLine("Only one?");
break;
case 100:
Console.WriteLine("100? That's a lot!");
break;
default:
Console.WriteLine("Input not recognized");
break;
}
Console.ReadLine();
}
}
}