Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1

    //program prompts users to enter E,A,B to compute total. If Z is entered than the sum of comissions is displayed
{
    class Program
    {
        static void Main(string[] args)
        {
           //declare and assign variables
            char letter;
            char quit= 'Z';
            char andrea= 'A';
            char brittany= 'B';
            char eric= 'E';
            const double COMISSION_BASE=0.10;
            double comission;
            double aTotal = 0;
            double bTotal = 0;
            double aSalesTotal;
            double eSalesTotal = 0;


            double sales=0;
            Console.WriteLine("what is your initial? Enter Z to quit"); //ask question

            //convert variables

            letter=Convert.ToChar(Console.ReadLine());
           //enter while loop
            while (letter!=quit) //if letter does not equal quit
            {

           if (letter== andrea ) //if letter equals "A"
           {

            comission=sales*COMISSION_BASE; //acummulate
            aTotal+= comission;
           }
            else if  (letter== brittany)  //if letter equals "B"
           {comission=sales*COMISSION_BASE; //accumulate
                bTotal+=comission;
            }
            else if (letter== eric) //if letter equals "e"
           {
             comission=sales*COMISSION_BASE; //accumulate
            eSalesTotal+=comission;
            }
            else
           {
                Console.WriteLine("Invalid person"); //if neither initial is entered
            Console.WriteLine("Enter next person or Z to quit");
            }}
            //if Z is entered display final amounts

            Console.WriteLine ("Andreas total comission is {0}"+ aTotal.ToString("N2"));
            Console.WriteLine("Brittany's total comission is {0}" +bTotal.ToString("N2"));
            Console.WriteLine("Eric's total comissions is {0}"+eSalesTotal.ToString("N2"));
            Console.ReadLine();
        }
    }
}
Posted
Updated 3-Nov-12 23:45pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Oct-12 22:40pm    
And..?

This is not a question.
--SA
adriancs 25-Oct-12 23:13pm    
I think he wants to say:
code shows no build errors but will not run PROPERLY AS PREDICTED. IT HAS ENDLESS LOOP.

1 solution

Your code has endless loop. The problem causes by this block:
C#
while (letter != quit)
{

}

If letter is not equal to quit, then this loop will never end.
You need to provide a function for user to modify letter and pause the loop before a new loop.
C#
while (letter != quit)
{
    // Ask your question inside the loop
    Console.Clear();
    Console.WriteLine("what is your initial? Enter Z to quit");
    letter = Convert.ToChar(Console.ReadLine());

    // Process sales and commission calculation
    switch(letter)
    {
        case    ....
        case    ....
        case    ....
        default ....
    }

    // Display result message
    Console.WriteLine("bla bla bla...");

    // Pause the loop, enable user to read message
    Console.ReadKey();
}
 
Share this answer
 
v4
Comments
phantom34 27-Oct-12 0:16am    
It worked! Thank you for your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900