In: Computer Science
Must be in C#
Create an application that determines the total due on purchases including sales tax and shipping charges. Allow the user to input any number of item prices. Use a do-while loop such that in the first iteration, you ask the user to enter the price for an item. Keep a counter variable to track the number of items the user has entered by incrementing its value at every iteration. As the last statement for the do{} construct, ask the user if they wish to enter more item prices. Re-execute the do-while loop if the user enters “yes”.
Shipping charges are determined based on the number of items purchased using the following chart (if necessary, use if/else statements for making this decision).
Fewer than 3 items $3.50
3 to 6 items $5.00
7 to 10 items $7.00
11 to 15 items $9.00
More than 15 items $10.00
In addition to the above, if the total purchase (before adding sales tax) is $100.00 or more, then provide free shipping. If the user is $10.00 or less away from reaching a total purchase of $100.00, then display a message prompting the user that they are “that many” dollars away from free shipping. This should be implemented in a way that allows the user to continue entering items if they are close to free shipping.
Sales tax of 7.75% is charged against the total purchase. Display an itemized summary to the user with the following information. Total purchase charge, number of items purchased, sales tax amount, shipping charge, and the grand total. Use proper format specifiers if necessary.
SOLUTION-
I have solve the problem in c# code with comments and screenshot
for easy understanding :)
CODE-
//C# CODE
using System;
class ItemSales {
public static double Price {get; set;}
public static double ShippingCharges {get; set;}
public static double GrandTotal {get;set;}
public static double SalesTax {get; set;}
public static void Main (string[] args) {
string choice = null;
int counter = 0;
Price = 0.0;
input:
do
{
Console.WriteLine("Enter price of item");
string num = Console.ReadLine();
Price =Price + Convert.ToDouble(num);
Console.WriteLine("Want to enter price of more item");
choice = Console.ReadLine();
counter++;
} while (choice.Equals("yes"));
if(Price <=90)
{
double diff = 100.0 - Price;
Console.WriteLine("You are $"+diff.ToString() +" away to get free
shipping");
Console.WriteLine();
goto input;
}
else if(Price >=100)
{
Console.WriteLine();
Console.WriteLine("Congratulations!!!, You got free
shipping");
Console.WriteLine();
}
if(counter < 3 )
{
ShippingCharges = 3.50;
}
else if(counter >=3 && counter <=6)
{
ShippingCharges= 5.00;
}
else if(counter >=7 && counter <=10)
{
ShippingCharges= 7.00;
}
else if(counter >=11 && counter <=15)
{
ShippingCharges= 9.00;
}
else if(counter >15)
{
ShippingCharges= 10.00;
}
SalesTax = (7.75 * Price)/100.0;
GrandTotal = SalesTax + Price;
//Total purchase charge, number of items purchased, sales tax
amount, shipping charge, and the grand total
Console.WriteLine("Total purchase charge is
$"+Price.ToString());
Console.WriteLine();
Console.WriteLine("Number of items purchased is
"+counter.ToString());
Console.WriteLine();
Console.WriteLine("Total Sales Tax amount is
$"+SalesTax.ToString());
Console.WriteLine();
Console.WriteLine("Shipping Charge is
$"+ShippingCharges.ToString());
Console.WriteLine();
Console.WriteLine("Grand Total amount is is
$"+GrandTotal.ToString());
}
}
Output:
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL
SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------