In: Computer Science
Shopping Cart App (C#)
Please create a C# Console (.NET Framework) application which reads from the user, the price of items in their shopping "cart". Be sure to tell the user how to stop (or ask them if they want to stop) entering prices.
Items can be priced any positive number greater than zero.
When the user has entered the prices for all items in their "cart", calculate the subtotal (the sum of all item prices).
Next, check if the user is a member of our Frequent Shopping Club. If so, take 10% off the subtotal price.
Finally, calculate the tax owed (the tax RATE is 4.5%), and then the total (subtotal + tax OWED = total).
Display the subtotal, discount (will be zero if not a member of the Frequent Shopping Club), tax owed, and total.
You should use While loops, IF statements, and TryParse statements to ensure all input is correctly entered.
If you have any doubts, please give me comment...
using System;
public class ShoppingCart{
public static void Main(){
char choice = 'Y';
char isFSCMember;
double price, discount=0, sub_total = 0, tax_owed, total;
while(choice=='Y' || choice=='y'){
Console.Write("Enter price of item: ");
Double.TryParse(Console.ReadLine(), out price);
if(price<0)
Console.WriteLine("Price can't be negative");
else
sub_total += price;
Console.Write("Do you want to continue(Y/N): ");
choice = Console.ReadKey().KeyChar;
Console.WriteLine();
}
Console.Write("Are you member of our Frequent Shopping Club(Y/N)? ");
isFSCMember = Console.ReadKey().KeyChar;
Console.WriteLine();
if(isFSCMember=='Y' || isFSCMember=='y')
discount = sub_total*0.10;
sub_total -= discount;
tax_owed = sub_total*(4.5/100);
total = sub_total + tax_owed;
Console.WriteLine("Subtotal: ${0}", sub_total.ToString("0.00"));
Console.WriteLine("Discount: ${0}", discount.ToString("0.00"));
Console.WriteLine("Tax Owed: ${0}", tax_owed.ToString("0.00"));
Console.WriteLine("Total: ${0}", total.ToString("0.00"));
}
}