- 3
If & else
A variety store give a 15% discount on sales totalling $300 or more. Write a C# program to request the cost of 3 items and print the amount the customer must pay.
4 Antworten
+ 3
First, this is not a question. Secondly, you have answered it yourself. Please remove it.
https://www.sololearn.com/discuss/1316935/?ref=app
+ 1
The message in console.write should be updated as second and third
+ 1
Because your multiply 0.15 so the finalPrice may have four decimal places. Convert to double again before displaying the final result.
0
static void Main(string[] args)
{
double item1Price, item2Price, item3Price;
double totalPrice,finalPrice;
//Input
Console.Write("Please enter the price of the first item:");
item1Price = Convert.ToDouble(Console.ReadLine());
Console.Write("Please enter the price of the first item:");
item2Price = Convert.ToDouble(Console.ReadLine());
Console.Write("Please enter the price of the first item:");
item3Price = Convert.ToDouble(Console.ReadLine());
//Processing
totalPrice = item1Price + item2Price + item3Price;
if (totalPrice >= 300)
{
finalPrice =totalPrice - (0.15 * totalPrice);
}
else
{
finalPrice = totalPrice;
}
//OutPut
Console.WriteLine("Final Price:{0:c}", finalPrice);
Console.ReadKey();
}