Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E,

Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E, or F). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Issue an error message for any invalid initials entered. Keep a running total of the amounts sold by each salesperson. After the user types Z or z for an initial, display each salespersons total, a grand total for all sales, and the name of the salesperson with the highest total.

***I need help handling an exception that C# is throwing. it is on this line >>> initial = Convert.ToChar(Console.ReadLine().ToUpper()); ***

***I just need help fixing that line so the exception will not happen and I can continue to run the program ***

Here is my code:

using System;

namespace HomeSales { class HomeSales { static void Main(string[] args) { char initial; double saleAmount; double totalSalesD=0; double totalSalesE=0; double totalSalesF=0; double grandTotal=0; double highestSales=0; string highestPerson;

do { Console.WriteLine("Enter a salesperson's initial"); Console.WriteLine("D/d for Danielle"); Console.WriteLine("E/e for Edward"); Console.WriteLine("F/f for Francis"); Console.WriteLine("Enter Z/z to display the total amount of sales: ");

initial = Convert.ToChar(Console.ReadLine().ToUpper());

if(initial != 'Z') { if (initial == 'D' || initial == 'E' || initial == 'F') { Console.WriteLine("Enter the sale amount for this salesperson: "); saleAmount = Convert.ToDouble(Console.ReadLine());

switch (initial) { case 'D': totalSalesD += saleAmount; break;

case 'E': totalSalesE += saleAmount; break;

case 'F': totalSalesF += saleAmount; break; default: break; } } else { Console.WriteLine("The intial is invalid, re-enter an initial."); } } } while (initial != 'Z'); grandTotal = totalSalesD + totalSalesE + totalSalesF;

Console.WriteLine("--------------------------------------------------------------");

Console.WriteLine("The total sales for Danielle is: {0,8}", totalSalesD.ToString("C"));

Console.WriteLine("The total sales for Edward is: {0,5}", totalSalesE.ToString("C"));

Console.WriteLine("The total sales for Francis is: {0,10}", totalSalesF.ToString("C"));

Console.WriteLine("The grand total for the overall amount of sales is: {0,10}", grandTotal.ToString("C"));

if (totalSalesD>totalSalesE) { highestSales = totalSalesD; highestPerson = "Danielle"; } else { highestSales = totalSalesE; highestPerson = "Edward"; }

if(totalSalesF>highestSales) { highestPerson = "Francis"; highestSales = totalSalesF; }

Console.WriteLine("{0} is the person with the highest total sales overall: {1:5}.", highestPerson, highestSales.ToString("C"));

Console.ReadKey(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

More Books

Students also viewed these Programming questions