Sunday 22 January 2017

Coffee Shopping Simple c# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
       
        static void Main(string[] args)
        {
            int TotalCoffeeCost = 0;
            Start:
            Console.WriteLine("Please select coffee size: 1-Small, 2- Medium, 3 - Large");
            int UserChoice = int.Parse(Console.ReadLine());
           switch(UserChoice)
           {
               case 1:
                   TotalCoffeeCost += 1;
                   Console.ReadLine();
                   break;
               case 2:
                   TotalCoffeeCost += 2;
                   Console.ReadLine();
                   break;
               case 3:
                   TotalCoffeeCost += 3;
                   Console.ReadLine();
                   break;
               default:
                   Console.WriteLine("your choice {0}  is invalid", UserChoice);
                   Console.ReadLine();
                   goto Start;
           }
            Decide:
           Console.WriteLine("Do you want to buy another coffee - Yes or No?");
           string UserDecision = Console.ReadLine();

           switch(UserDecision)
           {
               case "YES":
                   goto Start;
               case "NO":
                   break;
               default:
                   Console.WriteLine("Your choice {0} is Invalid . Please try again...",UserDecision);
                   goto Decide;

           }
           Console.WriteLine("Thank You for shopping with us");
           Console.WriteLine("Your bill cost = {0}", TotalCoffeeCost);
           Console.ReadLine();          
        }
    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.