944,080 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1665
  • C# RSS
Nov 6th, 2009
0

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

Expand Post »
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.

c# Syntax (Toggle Plain Text)
  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; Nov 6th, 2009 at 7:00 pm. Reason: Do not use CODE SNIPPED for asking questions. Use FORUM HREAD!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
choosenalpha is offline Offline
23 posts
since Nov 2009
Nov 6th, 2009
0
Re: Can I have some help on storing a running total and how to exit out for each section?
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....
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009
Nov 7th, 2009
1
Re: Can I have some help on storing a running total and how to exit out for each section?
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...
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Nov 10th, 2009
0
Re: Can I have some help on storing a running total and how to exit out for each section?
Click to Expand / Collapse  Quote originally posted by ddanbe ...
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,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
choosenalpha is offline Offline
23 posts
since Nov 2009
Nov 15th, 2009
0

I got it solved gang thanks!

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,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
choosenalpha is offline Offline
23 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: how to check which item is checked/selected in checkedlistbox
Next Thread in C# Forum Timeline: Check DataGridViewCheckBoxColumn





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC