I'm sure I'm missing something simple, but would like to ask if someone could set me on the right path. We have to write a program that requests the hours worked in a week, and a pay-rate, and then prints the gross earnings, taxes and the net pay.

#include <iostream>
#include <iomanip>

using namespace std ;

void display_menu(int &UserChoice) ;
float get_pay_rate(int Choice) ;
float get_hours(void) ;
float get_gross(float hours, float rate) ;
float get_taxes(float gross) ;

int main( )
{
	int Choice ;
	float gross, hours, rate, taxes, net ;
	
	do
	{
		display_menu(Choice) ;
		get_pay_rate(Choice) ;
	} while (Choice != 0) ;

	cout << "End" << endl ;

	rate = get_pay_rate(Choice) ;
	hours = get_hours() ;
	gross = get_gross(hours, rate) ;
	taxes = get_taxes(gross) ;

	cout << "Earnings \t Hours \t Rate" << endl ;
	cout << gross << "\t" << hours << "\t" << rate << endl ;
	cout << taxes << endl ;
	cout << net << endl ;

	return 0 ;
}
void display_menu(int &UserChoice)	
{
	// Display the menu
	cout << "------------------------------------------------------" << endl ;
	cout << "Enter the number for the desired pay rate, or action: " << endl ;
	cout << " 1. $ 8.75/hr" << endl ;
	cout << " 2. $ 9.33/hr" << endl ;
	cout << " 3. $10.00/hr" << endl ;
	cout << " 4. $11.20/hr" << endl ;
	cout << " 5. Quit" << endl ;
	cout << "------------------------------------------------------" << endl ;

	cout << "Enter your choice: ";
	cin >> UserChoice ;


	while ( ! (0 <= UserChoice && UserChoice <= 5 ))	
	{
		cout << "Invalid choice - Choices are: 1 to 5 " ;
	}

	cout << "\n\n";
	
}

float get_pay_rate(int Choice)
{
	double rate ;

	switch (Choice)
	{
	case 1:
		rate = 8.75 ;
		break ;
	case 2:
		rate = 9.33 ;
		break ;
	case 3:
		rate = 10.00 ;
		break ;
	case 4:
		rate = 11.20 ;
		break ;
	case 5:
		break ;
	
	}
	cout << endl ;
}

float get_hours(void) 
{
	int hours ;

	cout << "Enter hours for pay period: " << endl ;
	cin >> hours ;

	while ( ! (0.0 <= hours && hours <= 80.0) )
	{
		cout << "Check hours for valid entry" << endl ;

	}
}

float get_gross(float hours, float rate)
{
	float gross ;

	gross = hours * rate ;
}

float get_taxes(float gross) 
{
	double taxHeld, taxes ;
	double net ;

	if (gross < 300.00) 
		taxes = gross * .15 ;

	else 

	if (gross >= 300.00 && gross < 450.00) 
		taxes = gross * .20 ;

	else 

	if (gross >= 450.00)
		taxes = .25 ;

	taxHeld = gross*(taxes /100);
	net = gross - taxHeld;

}

The error(s) I'm receiving are get_hours, get_gross, etc. must return a value. Thank you!

Recommended Answers

All 2 Replies

All functions that do not have a return type of 'void' must return a value. To return a value from a function, just do the following:

return variableName;

where variableName is a variable type the same as the return type. This can also be a value, such as:

return 6;

if you're returning an int.

In your main function, where you call the function that should be returning something, you can set a variable to the function such as:

rate = get_pay_rate(Choice);

This will set rate equal to whatever value was returned by the function.

Thank you! I was staring at it and it wasn't coming to me! I'll fix my code and let you know if I need any more assistance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.