Write a c++ program that computes salary?

So I'm trying to write a program that computes the salary, and the user has to input the hours and the rate at which the person gets paid, and "write the definition of the function printCheck that prints (displays) the hours worked, rate per hour, and the salary and write the definition of the function main that tests each of these functions." Also if the hours worked are more than 40 then the rate is 1.5 the rate. I have to use void functions (we haven't studied strings or anything like that) this is what I have so far but I can't figure out what to do next could you please help me?


#include <iostream>
using namespace std;

void getHours (double hours);
void getRate (double rate);
void getSalary (double amount);
int main()
{
double rate;
double hours;
double amount;

getHours(hours);

getRate(rate);

return 0;
}
void getHours (double hours)
{
cout << " Enter the hours worked. " << endl;
cin >> hours;
cout << endl;
}
void getRate (double rate)
{
cout << " Enter the rate per hour at which you get paid." << endl;
cin >> rate;
cout << endl;
}
void getSalary (double amount)
{
double hours;
double rate;
amount = hours * rate;

if (hours > 40)
amount = hours * (rate * 1.5);
cout << " The total salary is: " << amount << endl;
}
In getHours, you're passing hours by value. What the user entered isn't returned and is lost when getHours exits.

In getRate, same issue.

getSalary is never called.

hours and rate are used in getSalary, but are never initialized.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
Last edited on
It's my first time here sorry.

So how do I make so that what the user enters is returned in getHours and getRate?

And how can I initialize hours and rate in getSalary?
Since you've been told to use void functions, you can't return the value out of the function.

Your only option is to make the variables global, which is a poor practice.
You think you can write this program in the correct way so I can see what's wrong with it?
Topic archived. No new replies allowed.