C#
using System;
public class LoopingCommision
{
public static void Main()
{
string SalesPeople, Sales;
char response;
Console.WriteLine("Do you want to caculate commision of a sales person? Y or N");
response = GetChar();
while (response == 'Y')
{
Console.WriteLine("Enter Sales persons inital? A, B or E ");
SalesPeople = Console.In.ReadLine();
if (SalesPeople =="A") Console.Out.WriteLine("Enter the ammout of sales for this sales person");
else if (SalesPeople =="B")Console.Out.WriteLine("Enter the ammout of sales for this sales person");
else if (SalesPeople =="E")Console.Out.WriteLine("Enter the ammout of sales for this sales person");
Sales = Console.In.ReadLine();
double Commision = Convert.ToDouble(Sales) / 10.0;
Console.WriteLine("The commision is {0}",Commision);
Console.Out.WriteLine("Do you want to enter more commisions? Y or N");
response = GetChar();
}
Console.WriteLine("Have a nece day!");
}
public static char GetChar()
{
string inputString;
char answer;
inputString = Console.In.ReadLine();
answer = Convert.ToChar(inputString);
return answer;
}
}
Simon66 pointsPosted Apr 6, 2007, 5:19 PM EDT
Hello, You might be looking for something like this : public class SalesPerson { private string _initials; private double _commissionAmount; public string Initials { get { return _initials; } set { _initials = value; } } public double CommissionAmount { get { return _commissionAmount; } set { _commissionAmount = value; } } public SalesPerson(string initials) { _initials = initials; } } and then inside your Main() function { List lstSalesPerson = new List(); lstSalesPerson.Add(new SalesPerson("A")); lstSalesPerson.Add(new SalesPerson("B")); lstSalesPerson.Add(new SalesPerson("E")); // you could add any other salesperson here, by the way.. while(...) { // read sales person initials here as you already do // parse the list of sales people and foreach (SalesPerson s in lstSalesPerson) if (s.Initials == SalesPeople) { Console.Out.WriteLine("Enter the ammout of sales for this sales person"); // read commission here Sales = Console.In.ReadLine(); double Commision = Convert.ToDouble(Sales) / 10.0; s.Commission += Commission; Console.WriteLine("The commision is {0}",Commision); break; } } // here you have all the commissions for each sales person inside the list lstSalesPerson } Hope this helps ! Simon