The following code in
c# is using only switch..case and do while loop. I think the following code is
self explanatory. So I don’t want to give explanation of the code.
using System;
namespace ConsoleApplication25
{
class Program
{
static void Main(string[] args)
{
int totalcoffeecost=0;
string userdecision=string.Empty;
do
{
int userchoice = -1;
do
{
Console.WriteLine("please
select your coffee size 1.small 2.medium 3.large");
userchoice = int.Parse(Console.ReadLine());
switch (userchoice)
{
case 1: totalcoffeecost
+= 1; break;
case 2: totalcoffeecost
+= 2; break;
case 3: totalcoffeecost
+= 3; break;
default: Console.WriteLine("your choice
{0} is invalid", userchoice); break;
}
}
while (userchoice != 1 && userchoice
!= 2 && userchoice != 3);
do
{
Console.WriteLine("DO YOU WANT
TO BUY ANOTHER COFFEE-yes or no");
userdecision = Console.ReadLine().ToUpper();
if (userdecision != "YES" &&
userdecision != "NO")
{
Console.WriteLine("your choice
{0} is invalid.please try again...", userdecision);
}
}
while (userdecision != "YES" &&
userdecision != "NO");
}
while (userdecision.ToUpper() != "NO");
Console.WriteLine("thankyou for shopping with us");
Console.WriteLine("billamount={0}",totalcoffeecost);
Console.ReadLine();
}
}
}
Output:
-------Thank you
Muthu karthikeyan,Madurai
No comments:
Post a Comment