Question
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,
***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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started