| | |
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
![]() |
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
Can I have some help on storing a running total and how to exit out for each section?
0
#1 17 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.
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)
using System; public class TubSales { public static void Main() { string inputString;//This grabs the user's response for the salespersons initial. char response; 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); double saleAmount = new double(); double saleAmount_A = new double(); double saleAmount_B = new double(); double saleAmount_E = new double(); double commission = 0.10 * saleAmount; while (response != 'Z') { if (response == 'A') { Console.WriteLine("Permitted user please enter the sale amount that you made."); inputString = Console.ReadLine(); saleAmount = Convert.ToDouble(inputString); saleAmount_A = commission; saleAmount_A += saleAmount; } if (response == 'B') { Console.WriteLine("Permitted user please enter the sale amount that you made."); inputString = Console.ReadLine(); saleAmount = Convert.ToDouble(inputString); saleAmount_B = commission; saleAmount_B += commission; } if (response == 'E') { Console.WriteLine("Permitted user please enter the sale amount that you made."); inputString = Console.ReadLine(); saleAmount = Convert.ToDouble(inputString); saleAmount_E = commission; saleAmount_E += commission; } } while (response == 'Z') 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")); } }
Last edited by peter_budo; 17 Days Ago at 7:00 pm. Reason: Do not use CODE SNIPPED for asking questions. Use FORUM HREAD!
•
•
Join Date: Sep 2009
Posts: 279
Reputation:
Solved Threads: 31
0
#2 17 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.
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....
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....
1
#3 17 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...
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
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
0
#4 13 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...
Regards,
![]() |
Similar Threads
- Counting pennies with a running total... (C++)
- Queueing Simulation (C++)
- Calculate Running total without ordered index (MySQL)
- how to program a simple calculator? (C)
- total per page (Visual Basic 4 / 5 / 6)
- keep running total of numbers (C++)
- need help asap :) (Java)
Other Threads in the C# Forum
- Previous Thread: how to check which item is checked/selected in checkedlistbox
- Next Thread: Check DataGridViewCheckBoxColumn
| Thread Tools | Search this Thread |
.net 3.5 access activedirectory advice algorithm analyst array asp asp.net broadcast c# code combobox commerce concurrency connection console contorl control cs4 database datagrid datagridview datastructure datetime dba degrees development directrobot disabled drawing ecommerce editor enabled enum eventhandlers excel file form formatting formbox gdi+ httpwebrequest index java keypress label linux list listview login marshalbyrefobject math mysql oracle packaging password path photoshop platform pointer post print programmer programming random remoting resourcefile richtextbox robot server sql sql-server stream string stringformatting table tables tcpclientchannel textbox uploadatextfile user usercontrol validate validation vb video visual visual-studio visualbasic webbrowser webdevelopemnt whileloop wia windows winforms working wpf write







