error C2062: type 'float' unexpected in program

I do not know how to fix error - I am trying to write a report from a

Page 1 of 1

3 Replies - 7261 Views - Last Post: 24 March 2009 - 10:37 PM Rate Topic: -----

#1 MissA86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 24-March 09

error C2062: type 'float' unexpected in program

Posted 24 March 2009 - 07:54 PM

Hello,

I am taking my first computer programming course in C++ this semester. I keep getting the same errors on my program below and I do not know how to fix it. The task in this program is to open a file with names, IDs, pay rates, and benefits and to calculate the taxes paid for each individual, and then subtract the taxes and benefits from weekly earnings and to produce a table in an output file. I keep getting the following two errors when I try to compile the program:

warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
error C2062: type 'float' unexpected

My code is below:

//COMP 140
//Project 3
//Due March 26, 2009
//Report Writer - Display employee information and tax rates. 

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

void header();
float detail(char firstname[20], char lastname[20], int ID, float payrate, int number);
float benefit(int number);

int _tmain(int argc, _TCHAR* argv[])
{
	ifstream infile;
	ofstream outfile;
	char firstname[20];
	char lastname[20];
	int ID;
	int number;
	float payrate;
	float taxtotal=0.0;
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	infile.open("MASTER[1].txt");
	outfile.open("MASTEROUTPUT.rtf");
	infile >> firstname >> lastname >> ID >> payrate >> number;
	
	header();

	while(infile)
	{
		cout << firstname << setw(5) << lastname << setw(5)<< ID;

float detail(char firstname[20], char lastname[20], int ID, float payrate, int number);

	}

	infile.close();
	outfile.close();
	cout << "The total tax paid by employees is " << taxtotal <<endl;


	return 0;
}

float detail(char firstname[20], char lastname[20], int ID, float payrate, int number)
{	

	float tax;
	float taxtotal=0;
	float weekly = (40*payrate);
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	tax = (.28*weekly);
	int linecount;
	linecount = 0;
	float takehome;
	using namespace std;
	float q = float benefit(int number);
	takehome = weekly-tax-q;
	linecount++;
	if(linecount > 15)
	{
		ofstream outfile;
		outfile << "\f";
		header();
		linecount = 0;
	}
	#include <iomanip>
	cout << setw(5) << weekly << setw(5) << tax << setw(5) << takehome;
	ifstream infile;
	infile >> firstname >> lastname >> ID >> payrate >> number;
	return (taxtotal = taxtotal+tax);
}


void header()
{
	using namespace std;
	cout << "First Name";
	cout << setw(10) << "Last Name" << setw(10) << "ID" << setw(10) << "Wages";
	cout << setw(10) << "Taxes" << setw(10) << "Take Home" <<endl;
	
}

float benefit(int number)
	{
		float cost;
		if(number = 0)
		{ 
			cost = 0.00;
		}
		if(number = 1)
		{
			cost = 8.00;
		}
		if(number = 2)
		{ 
			cost = 11.00;
		}
		if(number = 3)
		{
			cost = 13.00;
		}
		return(cost);
	}



Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: error C2062: type 'float' unexpected in program

#2 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: error C2062: type 'float' unexpected in program

Posted 24 March 2009 - 08:01 PM

    float takehome;
    using namespace std;
    float q = benefit(number);
    takehome = weekly-tax-q;


Welcome. Works like a charm.
EDIT: Welcome to DIC!

This post has been edited by Hyper: 24 March 2009 - 08:02 PM

Was This Post Helpful? 1

#3 MissA86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 24-March 09

Re: error C2062: type 'float' unexpected in program

Posted 24 March 2009 - 10:35 PM

Thank you very much - that helped!
Was This Post Helpful? 0
  • +
  • -

#4 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: error C2062: type 'float' unexpected in program

Posted 24 March 2009 - 10:37 PM

Welcome. Don't forget to use the "This post was helpful!" button.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1