Problem:
Th ree salespeople work at Sunshine Hot Tubs—Andrea,
Brittany, and Eric. Write a console-based application that
prompts the user for a salesperson's initial ('A', 'B', or 'E').
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
Question: it doesn't work, what should I do
What I have done so far:
char A, B, E, Z;
string userInputString, userInputAmountString;
char userInput;
double userInputAmount, tip =.10, comission, total;
do
{
Console.WriteLine("Please enter initial of the salesperson");
userInputString = Console.ReadLine();
userInput = Convert.ToChar(userInputString);
Console.WriteLine("Please enter the amount of a sale the saleperson made");
userInputAmountString = Console.ReadLine();
userInputAmount = Convert.ToDouble(userInputAmountString);
comission = userInputAmount * tip;
total = comission + userInputAmount;
}
while ( userInput == A || userInput == B || userInput == E );
Console.WriteLine("The total saleperson made is {0}", total);
Loading
VulpesPosted Jan 3, 2012, 6:39 PM
Also you're going to need an 'outer' infinite loop here to keep getting input until 'Z' is pressed when you can break out of the infinite loop and print the results.
As it's a bit trickier than the previous examples, I thought I'd complete it for you before it's time for me to turn in:
VulpesPosted Jan 4, 2012, 4:29 AM
Posted Jan 4, 2012, 12:31 AM
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
char initial;
double sAmountA=0, sAmountB=0, sAmountE=0, tip = .10, Acomission=0, Bcomission=0, Ecomission=0, Atotal=0, Btotal=0, Etotal=0;
Console.Write("Initial ");
initial = Convert.ToChar(Console.ReadLine());
while (true)
{
if (initial == 'A')
{
Console.Write("Sale $", sAmountA);
sAmountA = Convert.ToDouble(Console.ReadLine());
Acomission = sAmountA * tip;
Atotal = Acomission + Atotal;
Console.WriteLine("Comission {0}", Acomission.ToString("C"));
}
if (initial == 'B')
{
Console.Write("Sales $", sAmountB);
sAmountB = Convert.ToDouble(Console.ReadLine());
Bcomission = sAmountB * tip;
Btotal = Bcomission + Btotal;
Console.WriteLine("Comission {0}", Bcomission.ToString("C"));
}
if (initial == 'E')
{
Console.Write("Sale $", sAmountE);
sAmountE = Convert.ToDouble(Console.ReadLine());
Ecomission = sAmountE * tip;
Etotal = Ecomission + Etotal;
Console.WriteLine("Comission {0}", Ecomission.ToString("C"));
}
total:
if (initial == 'Z')
{
Console.WriteLine("A's total Comission {0}", Atotal.ToString("C"));
Console.WriteLine("B's total Comission {0}", Btotal.ToString("C"));
Console.WriteLine("E's total Comission {0}", Etotal.ToString("C"));
}
Console.WriteLine();
Console.Write("Initial ");
initial = Convert.ToChar(Console.ReadLine());
if (initial == 'Z')
{
Console.WriteLine("Total commission of each sales persons");
Console.WriteLine();
goto total;
}
}
}
}
}
Prime bPosted Jan 3, 2012, 9:17 PM
See, I don't understand the while (userInput != 'A' && userInput != 'B' && userInput != 'E' && userInput != 'Z');
To me it seems like if userInput NOT equals A or B or E or Z then proceed , but I thought it should be ==