954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# looping

Hi all, I am a newbie to C# and need help bad. I am to use looping (do,for, while or any combination).The program will accept a letter 'A' example and then end. What am i doing wrong.

Three salespeople work at Sunshine Hot Tubs-Andrea, Brittany, and Eric. Write a program 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 percent 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. Save the file as TubSales.cs.

using System;
class Program
{
    static void Main()
    {
        string inputString;//This grabs the user's response for the salespersons initial.
        char response;
        double saleAmount = new double();
        double saleAmountA = new double();
        double saleAmountB = new double();
        double saleAmountE = new double();
        double commissionA = (0.10 * saleAmountA);
        double commissionB = (0.10 * saleAmountB);
        double commissionE = (0.10 * saleAmountE);
        
        Console.WriteLine("Please enter a salesperson's initial('A' for Andrea, 'B' for Brittany and 'E' for Eric and 'Z'to display each saleperson's total commmission earned)");
        inputString = Console.ReadLine();
        response = Convert.ToChar(inputString);
        
        
           while(response == 'A')
            {
                Console.WriteLine("Please enter the sale amount that you made.");
                inputString = Console.ReadLine();
                saleAmount = Convert.ToDouble(inputString);
                saleAmountA = commissionA += (0.10 * saleAmount);
                
            while(response == 'B')
            {
                Console.WriteLine("Please enter the sale amount that you made.");
                inputString = Console.ReadLine();
                saleAmount = Convert.ToDouble(inputString);
                saleAmountA = commissionA += (0.10 * saleAmount);
                               
                while(response == 'E')
            {
                Console.WriteLine("Please enter the sale amount that you made.");
                   inputString = Console.ReadLine();
                saleAmount = Convert.ToDouble(inputString);
                saleAmountA = commissionA += (0.10 * saleAmount);
                
               while (response != 'Z')
                
               Console.WriteLine("The total commission for each salesperson is: Andrea with {0},Brittany with {1}and Eric with {2}."
                    , saleAmountA.ToString("C"),saleAmountB.ToString("C"), saleAmountE.ToString("C"));
                }
            }
        }

   }
  }
CeeGee
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Too many while loops!
Use one loop on line 15: while (response != 'Z') and start arranging your code from there.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

I have tried that, but i do not know where to put the 'do' or 'while' for the program to work.

CeeGee
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Just use a while. Here is an example http://msdn.microsoft.com/en-us/library/2aeyhxcd.aspx
A do ... while is a different kind of loop.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Can you please show me how to fix the program to do what the question is asking.This is due tomorrow.

CeeGee
Light Poster
26 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

how about the do and the for loop?

ronaldlazo
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Hi, ronaldlazo, welcome :)
Please try to avoid resurrecting "old" threads. Read the rules of this site.
Coming to think of it, this thread probably made me post this snippet

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: