### NEWBIE HELP

I have been working on this program for over a week. I can only use loops. Please help!!

I need this program to go through 3 sales people Reid, Nicole, and Jarid. Then allow the user to enter up to 4 sales amounts. I need the program to continue until the user enters Z. Then, the output should be the total sales for each sales person along with their commission which is .13 of sales. Here is what I have so far.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119`` ``````#include #include #include #include using namespace std; int main() { const char Reid[] = "Reid"; const char Jarid[] = "Jarid"; const char Nicole[] = "Nicole"; const char *name; char input; int number, salesReid = 1, // counter salesJarid = 1, salesNicole = 1, totalReid = 0, totalJarid = 0, totalNicole = 0; //ofstream outputFile; //string name; //set format for dollar values cout << fixed << showpoint << setprecision(2); //Get user to select Salesperson cout << "To enter sales for Reid, enter R.\n" << "To enter sales for Jarid, enter J.\n" << "To enter sales for Nicole, enter N.\n" << "Enter your choice: "; cin >> input; if( input == 'R') { name = Reid; } else if (input == 'J') { name = Jarid; } else if (input == 'N') { name = Nicole; } // input validation for name while (!(name == Reid || name == Jarid || name == Nicole)); { cout << "Enter the first letter of your first name in caps: "; cin >> input; } int sales; if( name == Reid ) { sales = salesReid; } else if (name == Jarid) { sales = salesJarid; } else if (name == Nicole) { sales = salesNicole; } cout << "How many sales amounts will you enter (Maximum is 4): "; cin >> number; // input validation number of sales entered if ((number <= 0) || (number > 4)) { cout << "Number is invalid may not be less than 1 or more " << "than 4.\n" << "Enter number of sales to be entered: "; cin >> number; } for (int count = 1; count <= number; count++) { cout << "Enter the amount for sale " << count << ": "; cin >> sales; } // Here the totals are stored //sales += sales; totalReid += sales; totalJarid += sales; totalNicole += sales; //salesReid += sales; //accumulate running total //totalNicole += sales; //totalJarid += sales; double commission = sales * .13; cout << "Commission earned for sales entered is: " << commission << endl; cout << "Total sales for Reid are: " << totalReid << endl; cout << "Total sales for Nicole are: " << totalNicole << endl; //outputFile << commission << endl; //outputFile << totalReid << endl; system ("pause"); return 0; } ``````
I can't figure out how to make it loop through the 3 sales people and total the sales.
Would you like to elaborate by what you mean by 3 sales people?

at line 30 add for(int x = 0; x < 3; x++){
to make it look 3 times at what I think you mean by loop three times,
you also have an extra } at line 88, although if you add what I said, it uses that extra }
Last edited on
Joshhua5... Thanks for the tip.. what I need this program to do is to create a report that tracks the sales of 3 sales people. – Reid, Jarid, and Nicole. I need to prompt the user for a salesperson’s initial R, J, or N... then allow the user to enter up to 4 sale amounts at a time for the salesperson. I need to calculate and display the salesperson’ s commission as 13% of the sales entered. Add the commission to a running total for that salesperson. The program should terminate when the user types a ‘Z’. A final report should display each salesperson’s total commission earned along with their average sales.

I know this is very basic however I am struggling with a few concepts. any tips would be greatly appreciated...
You need to extend your 4 loop where you ask for sales details to also include the math performed after the loop, otherwise only the last sale will be recorded.
Thanks! I just did that. Now I am struggling with the sales being added to the appropriate sales person. The way I have it, the sales all get added to all 3 sales people. I appreciate the tips!
Am I heading the right way?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190`` ``````#include #include #include #include using namespace std; int main() { const char Reid[] = "Reid"; const char Jarid[] = "Jarid"; const char Nicole[] = "Nicole"; const char *name; char input; int number, sales, salesReid = 0, // counter salesJarid = 0, salesNicole = 0, totalReid = 0, totalJarid = 0, totalNicole = 0; //set format for dollar values cout << fixed << showpoint << setprecision(2); //Get user to select Salesperson // need some type of loop here to continue until user enters "Z" for(int x = 0; x < 3; x++){ //this is only going to loop through 3 times... cout << "To enter sales for Reid, enter R.\n" << "To enter sales for Jarid, enter J.\n" << "To enter sales for Nicole, enter N.\n" << "Enter your choice: "; cin >> input; if( input == 'R') { cout << "How many sales amounts will you enter (Maximum is 4): "; cin >> number; // input validation number of sales entered if ((number <= 0) || (number > 4)) { cout << "Number is invalid may not be less than 1 or more " << "than 4.\n" << "Enter number of sales to be entered: "; cin >> number; } for (int count = 1; count <= number; count++) { cout << "Enter the amount for sale " << count << ": "; cin >> salesReid; } if (input == 'J') { cout << "How many sales amounts will you enter (Maximum is 4): "; cin >> number; // input validation number of sales entered if ((number <= 0) || (number > 4)) { cout << "Number is invalid may not be less than 1 or more " << "than 4.\n" << "Enter number of sales to be entered: "; cin >> number; } for (int count = 1; count <= number; count++) { cout << "Enter the amount for sale " << count << ": "; cin >> salesJarid; } if (input == 'N') { cout << "How many sales amounts will you enter (Maximum is 4): "; cin >> number; // input validation number of sales entered if ((number <= 0) || (number > 4)) { cout << "Number is invalid may not be less than 1 or more " << "than 4.\n" << "Enter number of sales to be entered: "; cin >> number; } for (int count = 1; count <= number; count++) { cout << "Enter the amount for sale " << count << ": "; cin >> salesNicole; } /*if(name == Reid ) { sales == salesReid; } else if (name == Jarid) { sales == salesJarid; } else if (name == Nicole) { sales == salesNicole; } */ // input validation for name /*while (!(name == Reid || name == Jarid || name == Nicole)); { cout << "Enter the first letter of your first name in caps: "; cin >> input; } int sales; if(name == Reid ) { sales = salesReid; } else if (name == Jarid) { sales = salesJarid; } else if (name == Nicole) { sales = salesNicole; } */ /*cout << "How many sales amounts will you enter (Maximum is 4): "; cin >> number; // input validation number of sales entered if ((number <= 0) || (number > 4)) { cout << "Number is invalid may not be less than 1 or more " << "than 4.\n" << "Enter number of sales to be entered: "; cin >> number; } for (int count = 1; count <= number; count++) { cout << "Enter the amount for sale " << count << ": "; cin >> sales; */ // Here the totals are stored //sales += sales; salesReid += salesReid; //totalReid += salesReid; //totalReid = salesReid + salesReid; //salesJarid += sales; //sales += salesNicole; //salesReid += sales; //accumulate running total //totalNicole += sales; //totalJarid += sales; } } double commission = sales * .13; cout << "Commission earned for sales entered is: " << commission << endl; cout << "Total sales for Reid are: " << sales << endl; cout << "Total sales for Nicole are: " << salesReid << endl; cout << "Total sales for Jarid are: " << totalReid << endl; //outputFile << commission << endl; //outputFile << totalReid << endl; } system ("pause"); } return 0; } ``````
You may find this interesting...

http://www.dreamincode.net/forums/topic/343554-need-help-with-code-c/

Either this person is in the same class as you or this is your post. Have you asked your teacher/professor for help?
I would also recommend learning about a switch statement, which would replace the input == char statements, but that's unrelated.

Maybe also move what's inside the input == char if statements, into their own functions to make it a bit easier to read.
Topic archived. No new replies allowed.