I’m current struggling with my code.
Supposedly, when the user buy an item after he press N the program will print the total cost and and the items he/she would like to buy… Please help me. By the way it is C#.
Can you share your ideas on how can i solve this? even in other language like c/c++ is appreciated.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VscodeCsharp
{
class Program
{
static void Main(string args)
{
string userchoice;
string username;
int qty;
int total=0;
int[] price = new int[5];
{
price[0]=45;
price[1]=65;
price[2]=55;
price[3]=40;
price[4]=500;
};
string[] coffeedrinks = new string[5]
{
"Cafe Latte",
"Cappucino",
"Espresso",
"Flat White",
"Long Black",
};
Console.WriteLine("Enter your name: ");
username =Console.ReadLine();
string userdecision = string.Empty;
do
{
Console.WriteLine(" _______________________________________________________");
Console.WriteLine("| |");
Console.WriteLine("| Grinder Coffee Shop! |");
Console.WriteLine("| |");
Console.WriteLine("|_______________________________________________________|");
Console.WriteLine("| | |");
Console.WriteLine("| Products | Prices |");
Console.WriteLine("|__________________________|____________________________|");
Console.WriteLine("| |");
Console.WriteLine("|[A] Cafe latte | 45$ |");
Console.WriteLine("|[B] Cappuccino | 65$ |");
Console.WriteLine("|[C] Espresso | 55$ |");
Console.WriteLine("|[D] Flat White | 40$ |");
Console.WriteLine("|[E] Long Black | 500$ |");
Console.WriteLine("|_______________________________________________________|");
Console.WriteLine("Enter your choice: ");
userchoice = Console.ReadLine();
Console.WriteLine("Enter Quantity: ");
qty = int.Parse(Console.ReadLine());
switch (userchoice.ToUpper())
{
case "A":
total +=qty*price[0];
userchoice = coffeedrinks[0];
break;
case "B":
total +=qty*price[1];
userchoice = coffeedrinks[1];
break;
case "C":
total +=qty*price[2];
userchoice = coffeedrinks[2];
break;
case "D":
total +=qty*price[3];
userchoice = coffeedrinks[3];
break;
case "E":
total +=qty*price[4];
userchoice = coffeedrinks[4];
break;
}
do{
Console.WriteLine("Do you want to order again? Yes or No (Y/N)");
userdecision = Console.ReadLine();
if (userdecision.ToUpper() != "Y" && userdecision.ToUpper() != "N")
{
Console.WriteLine("\n\"{0}\" is not a valid input! Please try again...",userdecision);
}
}while(userdecision.ToUpper() != "Y" && userdecision.ToUpper() != "N");
} while (userdecision.ToUpper() != "N");
Console.WriteLine("\nThank you for shopping with us...");
Console.WriteLine("{0} Your total bill amount is = {1}",username,total);
Console.WriteLine(userchoice);
}
}
}