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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
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;
} 

What is your problem?
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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
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.