In: Computer Science
You have been approached by the Statistics Canada to create a C# program to calculate the average salary of people with university degrees, college diplomas, and high school diplomas. Using a while loop, you are to process salary data until the user indicates that you should stop (there could be 0 or more data values). For each person processed, the program must first input an education type (char edType) (‘U’ or ‘u’ for university degrees, ‘C’ or ‘c’ for college diplomas, and ‘H’ or ‘h’ for high school) and then a salary (double salaryData). The program stops accepting input when the user enters a ‘Q’ or ‘q’ for quit (use a sentinel value while loop). Your main data processing loop should be conditioned on the fact that the user has not signalled quit. It might look something like:
while(char.ToUpper(edType) != ‘Q’)
This implies that like any sentinel value loop, you must seed the loop (input a value) PRIOR to entering the loop. Inside the loop the salary data is entered and processed. Once the main loop terminates, the average salary for each of the three education types should be printed out. Be sure to print an error message if the user enters an invalid education type or a negative salary.
//C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace salaryCalculator
{
class Program
{
static void Main(string[] args)
{
char edType;
double salary;
double sumUniversity = 0, sumCollege = 0, highSchool = 0;
int uniCounter = 0, collegeCounter = 0, highSchoolCounter =
0;
do
{
Console.Write("Enter education Type
((U)niversity,(C)ollege,(H)ighSchool, (Q)uit): ");
edType = Console.ReadKey().KeyChar;
switch(edType)
{
case 'U':
case 'u':
Console.Write("\nEnter salary: ");
salary = Double.Parse(Console.ReadLine());
if (salary < 0)
Console.WriteLine("Invalid salary");
else
{
sumUniversity += salary;
uniCounter++;
}
break;
case 'C':
case 'c':
Console.Write("\nEnter salary: ");
salary = Double.Parse(Console.ReadLine());
if (salary < 0)
Console.WriteLine("Invalid salary");
else
{
sumCollege += salary;
collegeCounter++;
}
break;
case 'H':
case 'h':
Console.Write("\nEnter salary: ");
salary = Double.Parse(Console.ReadLine());
if (salary < 0)
Console.WriteLine("Invalid salary");
else
{
highSchool += salary;
highSchoolCounter++;
}
break;
case 'q':
case 'Q':
break;
default:
Console.WriteLine("Not valid education type..Retry");
break;
}
} while (char.ToUpper(edType) != 'Q');
double avg1 = 0, avg2 = 0, avg3 = 0;
if(uniCounter>0)
{
avg1 = sumUniversity / uniCounter;
}
if(collegeCounter>0)
{
avg2 = sumCollege / collegeCounter;
}
if(highSchoolCounter>0)
{
avg3 = highSchool / highSchoolCounter;
}
//Print result
Console.WriteLine("University Average Salary = {0}\nCollege Average
Salary = {1}\nHigh School average salary = {2}",
avg1.ToString("C"), avg2.ToString("C"), avg3.ToString("C"));
//pause
Console.ReadLine();
}
}
}
//Output

//If you need any help regarding this solution.......please leave a comment..... thanks