2 Replies - 284 Views - Last Post: 24 February 2018 - 05:09 PM Rate Topic: -----

#1 ssterling1912   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-February 18

Can someone please help a beginner with a C Programming error.

Posted 24 February 2018 - 04:23 PM

So I am just learning C. Only been using it for a couple of weeks, so please bear with me. Basically I'm doing homework for school. I'm making a program to calculate gross pay for a set of employees. We have to use functions. I keep getting error code E0167 saying "argument float is incompatible with parameter type float." and c2440 saying function: cannot convert from float to float. I'm sure its something incredibly stupid, so please take it easy.

I cant figure out what I did wrong. Here is my function and line where I am getting the error.

Function:
void printInfo(int clockNum[], float wage[], float hours[], float otHours[], float gross[])
{
	printf("%06i\t, %.2f\t, %.1f\t, %.1f\t\t, %.2f\n", clockNum, wage, hours, otHours, gross);
	return(0);
}



And the line with both errors is in the main function:
while (i = 0, i < EMPLOYEES, i++)
	{
		printInfo(clockNum[i], wage[i], hours[i], otHours[i], gross[i]);
	}




Thanks for any assistance.

The whole program so far if you need to see it.
#include<stdio.h>

#define STHOURS 40.0f  // standard work week. 40 hours
#define OTWAGE 1.5f  // time and a half for overtime
#define EMPLOYEES 5  // number of employees (size of array)

float getHours(int clockNum);     //   all function prototypes
float getGross(float wage, float hours, float otHours);
void printInfo(int clockNum, float wage, float hours, float otHours, float gross);



// -----------------------------------------------------------------------------
// Function: getHours
// 
// Purpose:	Obtains input from user, number of hours worked per employee, stores in local variable
//			and passes back to calling function.
//
// Parameters: clockNum
//
// Returns:	hoursWorked
//-------------------------------------------------------------------------------


float getHours(int clockNum)
{
	float hoursWorked;
	printf("Emter hours worked for Employee %06i", clockNum);
	scanf_s("%f", &hoursWorked);

	return(hoursWorked);
}

//-------------------------------------------------------------------------------
// Function: getGross
//
// Calculates gross.  Stores in local variable, and passes back to calling function.
//
// Parameters: wage, hours, otHours
//
// Returns: totalGross
//--------------------------------------------------------------------------------

float getGross(float wage, float hours, float otHours)
{
	float totalGross = (wage * (hours - otHours)) + ((wage * OTWAGE) * otHours);
	return(totalGross);
}

//--------------------------------------------------------------------------------
// Function: printInfo
//
// Purpose: Prints all employee information to a table. 
//
// Parameter: clcokNum, wage, hours, otHours, gross
//
// Returns: void 
//---------------------------------------------------------------------------------

void printInfo(int clockNum[], float wage[], float hours[], float otHours[], float gross[])
{
	printf("%06i\t, %.2f\t, %.1f\t, %.1f\t\t, %.2f\n", clockNum, wage, hours, otHours, gross);
	return(0);
}

//---------------------------------------------------------------------------------
// Function: getOTHours
//
// Purpose: Checks to see if hours worked is over 40, if so stores just the hours 
//          to a local variable.
//
// Parameters: hours
//
// Returns: overtimeHours
//----------------------------------------------------------------------------------


float getOTHours(float hours)
{
	float overtimeHours;
	
	if (hours > STHOURS)
	{
		overtimeHours = hours - STHOURS;
	}
	else
	{
		overtimeHours = 0;
	}
	return(overtimeHours);
}

void main()
{
	int clockNum[EMPLOYEES] = { 98401, 526488, 765349, 034645, 127615 };  // Employee clock number
	float wage[EMPLOYEES] = { 10.60, 9.75, 10.50, 12.25, 8.35 };   //  Employee wage
	float hours[EMPLOYEES];  // hours worked per week 
	float otHours[EMPLOYEES];  // overtime hours worked per week
	float gross[EMPLOYEES];  // gross pay per week
	int i;  //  loop index

	printf("-----------------------------------------------------------------------\n");   // table header

	while (i = 0, i < EMPLOYEES, i++)   //  Run loop and calculate hours, overtime hours, and 
	{                                      // gross pay for each employee and sets it equal to array
		hours[i] = getHours(clockNum[i]);  //  emlement for i index. 
		otHours[i] = getOTHours(hours[i]);
		gross[i] = getGross(wage[i], hours[i], otHours[i]);
	}

	while (i = 0, i < EMPLOYEES, i++)   //  runs loop and prints out employee table
	{
		printInfo(clockNum[i], wage[i], hours[i], otHours[i], gross[i]);
	}

	printf("-----------------------------------------------------------------------\n");  // table header
	return(0);
}




Is This A Good Question/Topic? 0
  • +

Replies To: Can someone please help a beginner with a C Programming error.

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2620
  • View blog
  • Posts: 4,175
  • Joined: 21-June 11

Re: Can someone please help a beginner with a C Programming error.

Posted 24 February 2018 - 04:41 PM

According to your signature, your parameters are arrays (well, pointers), but you try to use them as if they were floats. You also seem to call the function with floats as arguments, so I'm guessing it's the signature that's wrong, not the body of the function.

PS: I assume you've left out some * when you re-typed the error messages. Otherwise they make no sense.
Was This Post Helpful? 0
  • +
  • -

#3 ssterling1912   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-February 18

Re: Can someone please help a beginner with a C Programming error.

Posted 24 February 2018 - 05:09 PM

Thank you for your help. I got it working now!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1