Can I have some help on storing a running total and how to exit out for each section?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 3
Reputation: choosenalpha is an unknown quantity at this point 
Solved Threads: 0
choosenalpha choosenalpha is offline Offline
Newbie Poster

Can I have some help on storing a running total and how to exit out for each section?

 
0
  #1
18 Days Ago
Hello Guys,

I am trying to code this assignment below but I can't seem to get the running total
stored for each user that I have listed below(A, B, E). Can someone guide me on how
I can store the running total for each user so that I can have it stored when the
user enters "Z"? I have searched on different webpages and forums but I have yet
to find one that helps? I joined this forum to help me in my assistance to
conquer .NET(C#)so that I can be a developer in this. Can someone assist me kindly?
(I am a current I.T. professional and this sucks that I can't seem to solve it, it seems
so simple.)

Assignment question:

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.

  1. using System;
  2. public class TubSales
  3. {
  4. public static void Main()
  5. {
  6. string inputString;//This grabs the user's response for the salespersons initial.
  7. char response;
  8. 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)");
  9. inputString = Console.ReadLine();
  10. response = Convert.ToChar(inputString);
  11. double saleAmount = new double();
  12. double saleAmount_A = new double();
  13. double saleAmount_B = new double();
  14. double saleAmount_E = new double();
  15. double commission = 0.10 * saleAmount;
  16. while (response != 'Z')
  17. {
  18.  
  19.  
  20. if (response == 'A')
  21. {
  22. Console.WriteLine("Permitted user please enter the sale amount that you made.");
  23. inputString = Console.ReadLine();
  24. saleAmount = Convert.ToDouble(inputString);
  25. saleAmount_A = commission;
  26. saleAmount_A += saleAmount;
  27. }
  28.  
  29.  
  30.  
  31. if (response == 'B')
  32. {
  33. Console.WriteLine("Permitted user please enter the sale amount that you made.");
  34. inputString = Console.ReadLine();
  35. saleAmount = Convert.ToDouble(inputString);
  36. saleAmount_B = commission;
  37. saleAmount_B += commission;
  38. }
  39.  
  40.  
  41.  
  42. if (response == 'E')
  43. {
  44. Console.WriteLine("Permitted user please enter the sale amount that you made.");
  45. inputString = Console.ReadLine();
  46. saleAmount = Convert.ToDouble(inputString);
  47. saleAmount_E = commission;
  48. saleAmount_E += commission;
  49. }
  50.  
  51. }
  52. while (response == 'Z')
  53. Console.WriteLine("The total commission for each salesperson respectively is: Andrea with {0}, Brittany with {1} and Eric with {2}.", saleAmount_A.ToString("C"), saleAmount_B.ToString("C"), saleAmount_E.ToString("C"));
  54. }
  55. }
Last edited by peter_budo; 18 Days Ago at 7:00 pm. Reason: Do not use CODE SNIPPED for asking questions. Use FORUM HREAD!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 287
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 31
jonsca jonsca is offline Offline
Posting Whiz in Training
 
0
  #2
18 Days Ago
Calculating commission at the beginning like that will just calculate it once, and with the wrong amount for the sale.
Firstly, turn the whole thing into a do while loop because you have a while at both ends and that doesn't make sense.
Then make commissionA, commissionB and commissionE variables. commissionA+=(0.10*saleAmount); and saleAmountA+=saleAmount; If it helps you, run through it on paper with the values your variables take on. You're most of the way there, just read up on some stuff.

Also, I think the code snippet heading is used more for folks that have a function they want to add to the library for the site....
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso
 
1
  #3
18 Days Ago
Remove line 52. At that point in your code, you know that response is Z(see previous while) Besides that you are creating what is called an endless while here. It will go on printing the output of your program for ever. You need this output only once.
B.T.W. be carefull when you use terms like I.T. professional...
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: choosenalpha is an unknown quantity at this point 
Solved Threads: 0
choosenalpha choosenalpha is offline Offline
Newbie Poster
 
0
  #4
14 Days Ago
Originally Posted by ddanbe View Post
Remove line 52. At that point in your code, you know that response is Z(see previous while) Besides that you are creating what is called an endless while here. It will go on printing the output of your program for ever. You need this output only once.
B.T.W. be carefull when you use terms like I.T. professional...
Ok thanks guys, let me try this now! Thanks a great deal for guiding me on this request.

Regards,
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: choosenalpha is an unknown quantity at this point 
Solved Threads: 0
choosenalpha choosenalpha is offline Offline
Newbie Poster

I got it solved gang thanks!

 
0
  #5
9 Days Ago
Originally Posted by choosenalpha View Post
Ok thanks guys, let me try this now! Thanks a great deal for guiding me on this request.

Regards,
I got it solved you all! Thanks for you help! I'll post my results here for future readers with the same problem.

Thanks,
Reply With Quote Quick reply to this message  
Reply

Tags
c#, whileloop

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC