I keep getting an output of zero, I don't know what's wrong..

#include <iostream>
using namespace std;
double determineCommissionRate(double totalCommission, double totalSales);
double determineBasePay(double basePay, double yearsWorked);

int main()
{
    double yearsWorked, totalSales, totalPay, totalCommission, basePay;

    cout << "Please enter the number of years you have worked at this company" << endl;
    cin >> yearsWorked;

    cout << "Please enter the total amount of sales, in dollars, generated for the month" << endl;
    cin >> totalSales;

    totalPay = totalCommission + basePay;

    cout << "Your total pay is " << totalPay << endl;
    return 0;
}


double determineCommissionRate(double totalCommission, double totalSales)
{
    if (totalSales <= 5000)
    {
        totalCommission = totalSales * .025;
    }

    else if ((totalSales >= 10000) || (totalSales < 5000))
    {
        totalCommission = totalSales * .0325;
    }

    else if ((totalSales >= 20000) || (totalSales < 10000))
    {
        totalCommission = totalSales * .0450;
    }

    else if ((totalSales >= 40000) || (totalSales < 20000))
    {
        totalCommission = totalSales * .0650;
    }

    else if (totalSales > 40000)
    {
        totalCommission = totalSales * .0925;
    }

    else
    {
        cout << "That is not a proper amount, please try again. " << endl;
    }

    return (totalCommission);
}

double determineBasePay(double basePay, double yearsWorked)
{
    if ((yearsWorked >= 1) || (yearsWorked < 5))
    {
        basePay = 500;
    }

    else if (yearsWorked >= 5)
    {
        basePay = 1000;
    }

    else
    {
        basePay = 0;
    }

    return (basePay);
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Because you never actually do anything to put numbers in totalCommission or basePay. It's just chance that they're set to zero. You're doing nothing with them.

You made some functions to calculate these values, but you never call the functions.

Edited 5 Years Ago by Moschops: n/a

You know enough to declare and define functions but you don't know how to actually use them?

double returnedValue = determineCommissionRate(totalCommission, totalSales);

Edited 5 Years Ago by Moschops: n/a

I'm all over the place, learning bits and pieces..

I'm still getting zero.

Back to the original question; now that you know how to call a function, and you know the the function returns a value, are you actually setting the value you want to change to that returned value?

Here's a simple example.

int x; // Have set no value. x could be anything.
x = giveMeAValue(); // x is now whatever value is returned by the function giveMeAValue()

Edited 5 Years Ago by Moschops: n/a

Yes, I want the function to return the value based on what the user inputs.

Yes, I want the function to return the value based on what the user inputs.

They already do.

Your functions have crazy input (you are inputting the basePay to a function whose job is to calculate the basePay - makes no sense, but since your function doesn't use the input basePay value, it makes no difference), but they do work.

I'm not sure you understand the concept of a returned value from a function. The function gives back a value; it is up to you to make something equal to that value. For example, in this code, the function giveMeAValue() returns a value, and x is set to that value.

x = giveMeAValue(); // x is now whatever value is returned by the function giveMeAValue()

Your functions almost look like you're trying to pass by reference to change the variable you want to change within the function, and get a returned value of that same variable. Definitely read up again on functions.

Edited 5 Years Ago by Moschops: n/a

Oo okay, I think I see what I was doing wrong, thanks for the help ^^

This article has been dead for over six months. Start a new discussion instead.