How can I get "total" to work with my "commission" code?
Mar 24, 2009 at 8:07pm Mar 24, 2009 at 8:07pm UTC
Hi people.
Basically, I've got this coursework that's due in for this Thursday.
It's pretty much finished, but I can't seem to get this last bit working.
Everything is fine except for the commission, which SHOULD work, provided I get this "personalTotal" double working. I know that I need to some how link it to the length of my vector/array thing, but I haven't got the faintest idea how to do that.
It needs to be incorporated with the "for" loop above it which has all the "char (156)" bits in it.
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
#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
int main()
{
int noOfSalesPeople = 0, temp = 0;
vector <double > productA; vector <double > productB; vector <double > productC; vector <double > totalProduct;
double companyTotal = 0;
double priceA = 50, priceB = 75, priceC = 150;
double com1, com2, com3;
//double personalTotal;
//double total = com1 + com2 + com3;
cout << " " << endl;
cout << "Please enter the number of sales people: " ;
cin >> noOfSalesPeople;
cout << " " << endl;
cout << " " << endl;
for ( int i = 0; i < noOfSalesPeople; i++ )
{
cout << "Sales Person " << i << ":" << endl;
cout << endl << "Amount of product A sold this month: " ; cin >> temp; productA.push_back ( temp*priceA );
cout << endl << "Amount of product B sold this month: " ; cin >> temp; productB.push_back ( temp*priceB );
cout << endl << "Amount of product C sold this month: " ; cin >> temp; productC.push_back ( temp*priceC );
totalProduct.push_back( productA [i] + productB [i] + productC [i] );
companyTotal += totalProduct [i];
cout << " " << endl;
cout << " " << endl;
}
for ( int i = 0; i < noOfSalesPeople; i++ )
{
cout << " " << endl;
cout << "Sales Person " << i << ":" << endl;
cout << " " << endl;
cout << "This months total sales for product A: " << endl;
cout << char (156) << productA [i] << endl;
cout << " " << endl;
cout << "This months total sales for product B: " << endl;
cout << char (156) << productB [i] << endl;
cout << " " << endl;
cout << "This months total sales for product C: " << endl;
cout << char (156) << productC [i] << endl;
cout << " " << endl;
cout << "This months total sales for this sales person: " << endl;
cout << char (156) << totalProduct [i] << endl;
cout << " " << endl;
cout << " " << endl;
//personalTotal [i] = productA [i] * 50 + productB [i] * 75 + productC [i] * 150;
}
//THIS BIT HERE:
// COMMISSION!!!!!
//if (personalTotal <= 1000)
//{
// com1 = personalTotal*0.05;
//}
//else if (personalTotal - 1000 <= 10000)
//{
// com2 = (personalTotal - 1000)* 0.03;
// }
//
// else if (personalTotal - 10000 <= 100000)
// {
// com3 = (personalTotal - 10000) * 0.01;
//
// }
So, basically, any help I could get with this would be greatly appreciated. I managed to do the rest of this piece by myself, and I haven't had any major problems so far.
Thanks in advance
Tom Yallop
Mar 25, 2009 at 4:20am Mar 25, 2009 at 4:20am UTC
where is personalTotal declared???
Mar 25, 2009 at 4:21am Mar 25, 2009 at 4:21am UTC
looks you have again done a blunder like the previous one {}
Mar 25, 2009 at 10:10am Mar 25, 2009 at 10:10am UTC
writetonsharma - personalTotal is declared at the top of the code. But I dropped it into note form so I could highlight the areas I'm having trouble with.
I know what you mean by the
{}
But you you know how I could get the commission to work for each person, the same as this "for loop" below?:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
for ( int i = 0; i < noOfSalesPeople; i++ )
{
cout << " " << endl;
cout << "Sales Person " << i << ":" << endl;
cout << " " << endl;
cout << "This months total sales for product A: " << endl;
cout << char (156) << productA [i] << endl;
cout << " " << endl;
cout << "This months total sales for product B: " << endl;
cout << char (156) << productB [i] << endl;
cout << " " << endl;
cout << "This months total sales for product C: " << endl;
cout << char (156) << productC [i] << endl;
cout << " " << endl;
cout << "This months total sales for this sales person: " << endl;
cout << char (156) << totalProduct [i] << endl;
cout << " " << endl;
cout << " " << endl;
//personalTotal [i] = productA [i] * 50 + productB [i] * 75 + productC [i] * 150;
}
Thanks
Tom Yallop
Topic archived. No new replies allowed.