You wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you
Question:
You wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis.
Now, using the code you wrote , Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values.
In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output statements as follows: WriteLine("This is an example: {0}", value.ToString("C", CultureInfo.GetCultureInfo("en-US")));
Tasks:
Use arrays for store salesperson names, initials, and accumulated sales values:
Array of type double declared to store accumulated sales values
1. Searched your code for a specific pattern: doubles*[]
Array of type char declared to store allowed initials
1. Searched your code for a specific pattern: chars*[]
Array of type string declared to store salesperson names
1. Searched your code for a specific pattern: strings*[]
The program's main functionality remains unchanged from Chapter 5, Programming Exercise 5.
1. Successful Output 1
Expected Output
50.00 25.00 60.00 135.00
2. Successful Output 2
Expected Output
90.00 10.00 50.00 150.00
3. Program accepts both upper and lower case value for a salesperson's initial
Expected Output
Daniellessolds*$15.00
Edwardssolds*$0.00
Francisssolds*$0.00
4. The program displays an error message for invalid initials
Sorry - invalid salesperson
Here is the code submitted in the previous assignment that it wants main functionality to not change:
using System;
using static System.Console;
using System.Globalization;
class HomeSales
{
static void Main()
{
// Write your main here.
string initial = "";
int dsale = 0;
int esale = 0;
int fsale = 0;
int total = 0;
while(initial != "z")
{
Write("Enter a sales person initial: ");
initial = ReadLine().ToLower();
if(initial == "d" || initial == "e" || initial == "f")
{
Write("Enter amount of sale: ");
int amount = Convert.ToInt32(ReadLine());
if(initial =="d")
dsale += amount;
else if(initial =="e")
esale += amount;
else if(initial == "f")
fsale += amount;
}
else {
if(initial != "z")
{
WriteLine("Sorry - invalid salesperson");
}
}
}
total = dsale + esale + fsale;
WriteLine("Danielle sold {0}", dsale.ToString("C",CultureInfo.GetCultureInfo("en-US")));
WriteLine("Edward sold {0}", esale.ToString("C",CultureInfo.GetCultureInfo("en-US")));
WriteLine("Francis sold {0}", fsale.ToString("C",CultureInfo.GetCultureInfo("en-US")));
WriteLine("Total sales were {0}", total.ToString("C",CultureInfo.GetCultureInfo("en-US")));
if(dsale > esale && dsale > fsale)
{
WriteLine("Danielle sold the most");
}
else if(esale > dsale && esale > fsale)
{
WriteLine("Edward sold the most");
}
else if(fsale > dsale && fsale > esale)
{
WriteLine("Francis sold the most");
}
else
{
WriteLine("There was a tie");
}
}
}
Business Statistics in Practice
ISBN: 978-0077404741
6th edition
Authors: Bruce Bowerman, Richard O'Connell