I need help with function part of this program

Weekly pay program with four functions and switch

Page 1 of 1

2 Replies - 478 Views - Last Post: 03 March 2009 - 05:05 AM Rate Topic: -----

#1 josephyballew  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-March 09

I need help with function part of this program

Posted 02 March 2009 - 07:49 PM

/***************************************************************************************
program6.cpp - This program computes 4 different types of pay types.

input:EmpNum, code, AnualSal, hour, wage, gross_wk_sales, pieces, amount
output: Weekly gross pay

***************************************************************************************/

#include "stdafx.h"

float Calculate1(float AnualSal);
float Calculate2(float hours, float wage);
float Calculate3(float gross_wk_sales);
float Calculate4(int pieces, float amount);

int main(void)
{
	int EmpNum;
	int code;
	float AnualSal;
	float hours;
	float wage;
	float gross_wk_sales;
	int pieces;
	float amount;
	float pay;
	float WP1;
	float WP2;
	float WP3;
	float WP4;

	printf("Enter employee number\n");
	scanf("%d",&EmpNum);

	printf("Enter employee code\n");
	scanf("%d",&code);

	while (code > 0 && code < 5)
	{
		while (EmpNum != 0)
		{
			switch (code)
			{
			   case 1:
           
				   printf("Enter anually salary\n");
	               scanf("%.2f", &AnualSal);

				   Calculate1(AnualSal);
				   

				   break;

			   case 2:
                 
				   printf("Enter number of hours worked\n");
	               scanf("%.2f", &hours);

				   printf("Enter hourly wage\n");
	               scanf("%.2f", &wage);

				   pay = Calculate2(hours, wage);

			       break;

			   case 3:

				   printf("Enter gross weekly sales\n");
	               scanf("%.2f", &gross_wk_sales);

                   pay = Calculate3(gross_wk_sales);

                   break;

			   case 4:

				   printf("Enter number of pieces\n");
	               scanf("%.2f", &pieces);

				   printf("Enter amount per piece\n");
	               scanf("%.2f", &amount);			   

				   pay = Calculate4(pieces, amount);

				   break;
			   default:
				   printf("%.2f\n", EmpNum);
                   printf("%.2f\n", pay);
		     }
		}
			printf("Invalid code\n");
		
     }


return 0;
}

/**********************************************************************************
Calculate1: Calculates gross weekly pay

input:anual salary
output:weekly gross pay

***********************************************************************************/
    
float Calculate1(float AnualSal)
{
 float WP1;
 

	WP1=AnualSal/52;          /* computes weekly pay*/ 

return WP1;
}

/**********************************************************************************
Calculate2: Calculates gross weekly pay including overtime.

input: hours,wage
output:weekly gross pay

**********************************************************************************/
float Calculate2(float hours, float wage)
{
float WP2;
  
  if (hours > 40)
        
	  WP2=hours * wage + ((hours-40) *1.5);  /* computes weekly pay*/ 

  else

      WP2=hours * wage;      

return WP2;
}
/**********************************************************************************
Calculate3:  Calculates gross weekly pay
input: gross_wk_sales
output:weekly pay

**********************************************************************************/
float Calculate3(float gross_wk_sales)
{
float WP3;

	WP3=250+(gross_wk_sales  * .057);         /* computes weekly pay*/ 

return WP3;
}
/**********************************************************************************
Calculate:  Calculates gross weekly pay
input: pieces, amount
output:weekly pay

**********************************************************************************/
float Calculate4(int pieces, float amount)
{
float WP4;

	WP4= pieces * amount;         /* computes weekly pay*/ 

return WP4;
}


*edit: Please use code tags in the future, thanks! :code:

This post has been edited by Martyr2: 02 March 2009 - 07:52 PM


Is This A Good Question/Topic? 0
  • +

Replies To: I need help with function part of this program

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,851
  • Joined: 18-April 07

Re: I need help with function part of this program

Posted 02 March 2009 - 07:53 PM

What exactly is the problem with the code? Please outline where you are having trouble and any error messages you are getting. A well formed question is worth its weight and gold.

Thanks for helping us help you! :)
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,217
  • Joined: 23-August 08

Re: I need help with function part of this program

Posted 03 March 2009 - 05:05 AM

Please put your question into the body of the post, rather than the description field.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1