Question: In Chapter 5, you wrote a C# GarageSale application for the Anderson,
ID: 3701941 • Letter: Q
Question
Question: In Chapter 5, you wrote a C# GarageSale application for the Anderson, Bowman, and Claxton families. The program prompts the user for a family initial (an uppercase or lowercase A, B, or C). The C# program continues while the user does not type Z, and it displays each family's total sales as well as the grand total made at the garage sale. Now, modify the program to use arrays to store the family names, allowed initials, and accumulated sales values. The Original Application in Chapter 5: The Anderson, Bowman, and Claxton families are running their annual garage sale. Write C# a console-based application named GarageSale that prompts the user for a family initial (A, B, or C). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Keep a running total of the amount earned by each family. After the user types Z or z for an initial, display each family's total as well as a grand total made at the garage sale.Explanation / Answer
Solution:
code:
using System;
class Program
{
static void Main(string[] args)
{
double familyA = 0;
double familyB = 0;
double familyC = 0;
double grandTotal = 0;
double saleAmount = 0;
string familyInitial;
double inputSale;
Console.Write("Enter your family initial A, B, or C: ");
familyInitial = Console.ReadLine();
Console.Write("Enter sale amount $");
inputSale = Convert.ToDouble(Console.ReadLine());
saleAmount = Convert.ToDouble(inputSale);
while (true)
{
if (familyInitial == "A" || familyInitial == "a")
{
familyA += saleAmount;
}
else if (familyInitial == "B" || familyInitial == "b")
{
familyB += saleAmount;
}
else if (familyInitial == "C" || familyInitial == "c")
{
familyC += saleAmount;
}
grandTotal = grandTotal + inputSale;
Console.Write("Enter your family initial A, B, or C(Z to exit): ");
familyInitial = Console.ReadLine();
if(familyInitial == "Z" || familyInitial == "z")
{
break;
}
Console.Write("Enter sale amount $");
inputSale = Convert.ToDouble(Console.ReadLine());
saleAmount = Convert.ToDouble(inputSale);
}
Console.WriteLine("Family A: {0}", familyA);
Console.WriteLine("Family B: {0}", familyB);
Console.WriteLine("Family C: {0}", familyC);
Console.WriteLine("Your Grand Total: {0} ", grandTotal);
}
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.