-
Loop issues.
My assignment:
Write a program that asks the user for a salesperson's initial. While the user does not type 'Z', continue by prompting for the amount of a sale the salesperson made. Calculate the salesperson's commission as 10% of the sale amount and add the commission to a running total for that salesperson. After the user types 'Z' for an initial, display each salesperson's total commission earned.
Here's what I have so far. I cannot get my results to print after entering 'Z'. What am I doing wrong?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TubSales
{
class Program
{
static void Main(string[] args)
{
String initial;
double sales;
double com = 0.10;
double totalSalesA = 0;
double totalSalesB = 0;
double totalSalesE = 0;
Console.WriteLine("Enter Sales Persons First Intial: ");
initial = Console.ReadLine().ToUpper();
Console.WriteLine("Enter Sales amount: ");
sales = Convert.ToDouble(Console.ReadLine());
while (initial != "Z")
{
if (initial == "A")
{
totalSalesA = totalSalesA + sales;
}
if (initial == "B")
{
totalSalesB = totalSalesB + sales;
}
if (initial == "E")
{
totalSalesE = totalSalesE + sales;
}
Console.WriteLine("Enter Sales Person's First Intial: ");
initial = Console.ReadLine().ToUpper();
Console.WriteLine("Enter Sales amount: ");
sales = Convert.ToDouble(Console.ReadLine());
}
if (initial == "Z")
{
Console.WriteLine("Commission for Andrea is: {0}", totalSalesA * com);
Console.WriteLine("Commission for Brittany is: {0}", totalSalesB * com);
Console.WriteLine("Commission for Eric is: {0}", totalSalesE * com);
}
}
}
}
-
After you enter 'Z', does the console window close? I'm guessing that the output is being written to the window, but the window is closing before you can see it. Try putting a Console.ReadLine() at the end of your program to keep the window open until you hit Enter.