2 Replies - 194 Views - Last Post: 20 December 2011 - 12:58 AM Rate Topic: -----

#1 angel@paripari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 11

why is it the output is only referring to the last user input?

Posted 20 December 2011 - 12:24 AM


#include <iostream>
#include <iomanip>
using namespace std;

//function prototype
void show(void);
void display(void);
double totalsales(double sales1, double sales2, double sales3);

//double grandtotal(double totalsales1, double totalsales2, double totalsales3);

int main()
{
    //variable declaration

    int level;
    double hours, overtime_rate;
    double total = 0;
    const int salesperson = 2;
    string employee[salesperson];
    string best_employee_display;
    const double price_product1 = 100.00;
    const double price_product2 = 50.00;
    const double price_product3 = 10.00;
    double product1, product2, product3;
    double sales1[salesperson];
    double sales2[salesperson];
    double sales3[salesperson];
    double totalsales[salesperson];
    double grandtotal;


    show();
    for (int i=0; i<salesperson; i++)
    {
        cout << "NAME OF EMPLOYEE: " ;
        cin >> employee[i] ;
        cout << "CURRENT LEVEL (1/2/3): ";
        cin >> level;

    switch (level)
    {
        case 1:
            cout << "Professional\n";
            cout << "HOURS WORKED : ";
            cin >> hours;
                    {
                        if (level==1)
                        {
                            overtime_rate = hours * 20;
                        }
                        else if (level==2)
                        {
                            overtime_rate = hours * 10;
                        }
                        else
                            overtime_rate = hours *5;
                    }

            cout << "Overtime Rate: RM" <<overtime_rate<< ".";
            cout << "\nPRODUCT 1 SOLD: " ;
            cin >> product1;
            cout << "PRODUCT 2 SOLD: " ;
            cin >> product2;
            cout << "PRODUCT 3 SOLD: " ;
            cin >> product3;
            cout << endl;
            break;

        case 2:
            cout << "Armatur\n";
            cout << "HOURS WORKED : ";
            cin >> hours;
                {
                    if (level==1)
                    {
                        overtime_rate = hours * 20;
                    }
                    else if (level==2)
                    {
                        overtime_rate = hours * 10;
                    }
                    else
                        overtime_rate = hours *5;
                }
            cout << "Overtime Rate: RM" <<overtime_rate<< ".";
            cout << "\nPRODUCT 1 SOLD: " ;
            cin >> product1;
            cout << "PRODUCT 2 SOLD: " ;
            cin >> product2;
            cout << "PRODUCT 3 SOLD: " ;
            cin >> product3;
            cout << endl;
            break;

        case 3:
            cout << "Trainee\n";
            cout << "HOURS WORKED : ";
            cin >> hours;
                {
                    if (level==1)
                    {
                        overtime_rate = hours * 20;
                    }
                    else if (level==2)
                    {
                        overtime_rate = hours * 10;
                    }
                    else
                        overtime_rate = hours *5;
                }

            cout << "Overtime Rate: RM" <<overtime_rate<< ".";
            cout << "\nPRODUCT 1 SOLD: " ;
            cin >> product1;
            cout << "PRODUCT 2 SOLD: " ;
            cin >> product2;
            cout << "PRODUCT 3 SOLD: " ;
            cin >> product3;
            cout << endl;
            break;


        default:
            cout << "Invalid! Please refer to HR Department.\n";
            break;

        }//end of switch case
    }//end of for loop


    for (int j=0; j<salesperson; j++)
    {
        total = total + sales1[j];
        sales1[j] = product1 * price_product1;
        sales2[j] = product2 * price_product2;
        sales3[j] = product3 * price_product3;
        totalsales[j] = sales1[j] + sales2[j] + sales3[j];
    }


    for (int m=0; m<salesperson; m++)
    {
        total = total + sales2[m];
        sales1[m] = product1 * price_product1;
        sales2[m] = product2 * price_product2;
        sales3[m] = product3 * price_product3;
        totalsales[m] = sales1[m] + sales2[m] + sales3[m];
    }

    for (int p=0; p<salesperson; p++)
    {
        total = total + sales3[p];
        sales1[p] = product1 * price_product1;
        sales2[p] = product2 * price_product2;
        sales3[p] = product3 * price_product3;
        totalsales[p] = (sales1[p] + sales2[p] + sales3[p]);
    }


    display();

    cout << "_____________________________________________________"
		 << "__________________________";
    cout << "\nEmployee\tProduct1\tProduct2\tProduct3\tTotal Sales(RM)"<< endl;
    cout << "_____________________________________________________"
		 << "__________________________\n";



    for (int k=0; k<salesperson; k++)
    {
        cout << employee[k] << "\t\t" << fixed << setprecision(2)
             << sales1[k] << "\t\t" << fixed << setprecision(2)
             << sales2[k] << "\t\t" << fixed << setprecision(2)
             << sales3[k] << "\t\t" << fixed << setprecision(2)
             << totalsales[k] << "\t\t" << fixed << setprecision(2) << endl;
    }

return 0;
}

void show(void)
{

    cout << "\tThis is a program that will print out a sale slip for three"
         << "\n\tsalespersons. There are three levels or current position"
         << "\n\tor job which is professional,armature and trainee.For each"
         << "\n\tlevel of job, it will be differences in the rate of working"
         << "\n\tovertime. Each salesperson has to sell three products."<<endl
         << "-----------------------------------------------------"
         << "--------------------------\n\n\n";
}

void display(void)
{
    cout << "\n\tThe total sales for each sales person are displayed at the"
         << "\n\tend of each row. Price for Product1 is RM100. Price for"
         << "\n\tProduct2 is RM50. And the price for Product3 is RM10."
         << "\n-----------------------------------------------------"
         << "--------------------------\n\n\n"
         << "\t\t<--------------- Products ------------->\n";
}

double totalsales(double sales1, double sales2, double sales3)
{
    double totalsales;
    totalsales = (sales1 + sales2 + sales3);
    return totalsales;
}




Is This A Good Question/Topic? 0
  • +

Replies To: why is it the output is only referring to the last user input?

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: why is it the output is only referring to the last user input?

Posted 20 December 2011 - 12:43 AM

Your input for the first salesperson's sales by product is going into the variables product1, product2 and product3, and then the input for the second salesperson's sales goes into the same three variables, so you are overwriting the first person's information.

If you want to wait to calculate the sales in RM after all of the input is finished, you should save each salesperson's unit sales amounts separately in an array. Otherwise, calculate the sales in RM for each salesperson immediately as the unit sales are entered.
Was This Post Helpful? 1
  • +
  • -

#3 angel@paripari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 11

Re: why is it the output is only referring to the last user input?

Posted 20 December 2011 - 12:58 AM

View Postr.stiltskin, on 20 December 2011 - 12:43 AM, said:

Your input for the first salesperson's sales by product is going into the variables product1, product2 and product3, and then the input for the second salesperson's sales goes into the same three variables, so you are overwriting the first person's information.

If you want to wait to calculate the sales in RM after all of the input is finished, you should save each salesperson's unit sales amounts separately in an array. Otherwise, calculate the sales in RM for each salesperson immediately as the unit sales are entered.


thank you. does it means,if i want to make it easier, then i need to calculate the unit sales amount n directly keep it as sales for each product?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1