GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Nov-2009, 07:21
abdaalh abdaalh is offline
New Member
 
Join Date: Nov 2009
Posts: 4
abdaalh is on a distinguished road

Write function getHoursRate that asks to inp the inp variables to initiliaze in main


Consider the definition of the function main:
int main ()
{
float rate, hours;
float amount;
.
.
.
}
Write the following definitions:
a. Write the definition of the function getHoursRate that prompts the user to input the hours worked and rate per hour to initialize the variables hours and rate of the function main.
b. Write the definition of the value-returning function paycheck that calculates and returns the amount to be paid to an employee based on the hours worked and rate per hour. The hours worked and rate per hour are stored in the variables hours and rate, respectively, of the function main. The formula for calculating the amount to be paid is as follows: for the first 40hours, the rate is the given rate; for hours over 40, the rate is 1.5 times the given rate.
c. Write the definition of the function printCheck that prints the hours worked, rate per hour, and the amount due.
d. Complete the definition of the function main that tests each of these functions.

THIS IS MY PROGRAM AND I KEEP GETTING THE SAME ERRORS:
error C2660: 'getHoursRate' : function does not take 0 arguments
error C2660: 'paycheck' : function does not take 0 arguments
error C2660: 'printCheck' : function does not take 0 arguments
error C2082: redefinition of formal parameter 'rate'
error C2082: redefinition of formal parameter 'hours'

CPP / C++ / C Code:
#include <iostream>
using namespace std;
void getHoursRate (float rate, float hours);
void paycheck(float rate, float hour);
void printCheck(float rate, float hours, float amount);

void main()
{
	float rate, hours;
	float amount;

	getHoursRate();
	paycheck();
	printCheck();
}

void getHoursRate (float rate, float hours)
{
	float rate, hours;

	cout<<"Enter Number Of Hours Worked: ";
	cin>>hours;
	cout<<"Enter Rate Per Hour";
	cin>>rate;
}

void paycheck(float rate, float hours)
{
	float amount;

	if (0<=hours && hours<=40)
		{amount = rate * hours;
		cout<<"\nThe Amount Due Is: "<<amount<<endl;}
	else
		{amount = rate * 1.5 * hours;
		cout<<"\nThe Amount Due Is: "<<amount<<endl;}
}

void printCheck(float rate, float hours, float amount)
{
            cout<<"\nThe Number Of Hours Is: "<<hours;

	if (0<=hours && hours<=40)
		{rate = rate;
		cout<<"The Rate Is: "<<rate<<endl;}
	else
		{rate = 1.5 * rate;
		cout<<"The Rate Is: "<<rate<<endl;}

	cout<<"The Amount Due Is: "<<amount<<endl;
}
Last edited by LuciWiz : 10-Nov-2009 at 08:08. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 10-Nov-2009, 07:32
abdaalh abdaalh is offline
New Member
 
Join Date: Nov 2009
Posts: 4
abdaalh is on a distinguished road

Re: Write function getHoursRate that asks to inp the inp variables to initiliaze in main


I tries doing this:

CPP / C++ / C Code:
#include <iostream>
using namespace std;
void getHoursRate ();
void paycheck(float rate, float hour);
void printCheck(float rate, float hours, float amount);

void main(float rate, float hours, float amount)
{
	float rate, hours;
	float amount;

	getHoursRate();
	paycheck();
	printCheck();
}

void getHoursRate ()
{
	float rate, hours;

	cout<<"Enter Number Of Hours Worked: ";
	cin>>hours;
	cout<<"Enter Rate Per Hour";
	cin>>rate;
}

void paycheck(float rate, float hours)
{
	float amount;

	if (0<=hours && hours<=40)
		{amount = rate * hours;
		cout<<"\nThe Amount Due Is: "<<amount<<endl;}
	else
		{amount = rate * 1.5 * hours;
		cout<<"\nThe Amount Due Is: "<<amount<<endl;}
}

void printCheck(float rate, float hours, float amount)
{
	cout<<"\nThe Number Of Hours Is: "<<hours;

	if (0<=hours && hours<=40)
		{rate = rate;
		cout<<"The Rate Is: "<<rate<<endl;}
	else
		{rate = 1.5 * rate;
		cout<<"The Rate Is: "<<rate<<endl;}

	cout<<"The Amount Due Is: "<<amount<<endl;
}

and i got these errors:

error C2082: redefinition of formal parameter 'rate'
error C2082: redefinition of formal parameter 'hours'
error C2082: redefinition of formal parameter 'amount'
error C2660: 'paycheck' : function does not take 0 arguments
error C2660: 'printCheck' : function does not take 0 arguments
Last edited by LuciWiz : 10-Nov-2009 at 08:09. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #3  
Old 10-Nov-2009, 07:41
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 815
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Write function getHoursRate that asks to inp the inp variables to initiliaze in main


You will need to find a way to return the hours and rate variables back to the main() function. You should either pass the parameters by reference or pass the pointers to them:

CPP / C++ / C Code:
// Pass by reference

int main ()
{
  float rate, hours;
  float amount;

  // This is how you would call the function
  getHoursRate(rate, hours);
} 

void getHoursRate(float& rate, float& hours)
{
  cout << "Enter Number Of Hours Worked: ";
  cin >> hours;
  cout << "Enter Rate Per Hour";
  cin >> rate;
}

CPP / C++ / C Code:
// Pass by pointer

int main ()
{
  float rate, hours;
  float amount;

  // This is how you would call the function
  getHoursRate(&rate, &hours);
} 

void getHoursRate(float* rate, float* hours)
{
  cout << "Enter Number Of Hours Worked: ";
  cin >> *hours;
  cout << "Enter Rate Per Hour";
  cin >> *rate;
}
  #4  
Old 10-Nov-2009, 08:17
abdaalh abdaalh is offline
New Member
 
Join Date: Nov 2009
Posts: 4
abdaalh is on a distinguished road

Re: Write function getHoursRate that asks to inp the inp variables to initiliaze in m


CPP / C++ / C Code:
#include <iostream>
using namespace std;
void getHoursRate (double rate, double hours);
void paycheck(double rate, double hour);
void printCheck(double rate, double hours, double amount);

void main()
{
	double rate, hours;
	double amount;

	getHoursRate(rate, hours);
	paycheck(rate, hours);
	printCheck(rate, hours, amount);
}

void getHoursRate (double rate, double hours)
{
	cout<<"Enter Number Of Hours Worked: ";
	cin>>hours;
	cout<<"Enter Rate Per Hour: ";
	cin>>rate;
}

void paycheck(double rate, double hours)
{
	float amount;

	if (0<=hours && hours<=40)
		{amount = rate * hours;
		cout<<"\nThe Amount Due Is: "<<amount<<endl;}
	else
		{amount = rate * 1.5 * hours;
		cout<<"\nThe Amount Due Is: "<<amount<<endl;}
}

void printCheck(double rate, double hours, double amount)
{
	cout<<"\nThe Number Of Hours Is: "<<hours;

	if (0<=hours && hours<=40)
		{rate = rate;
		cout<<"The Rate Is: "<<rate<<endl;}
	else
		{rate = 1.5 * rate;
		cout<<"The Rate Is: "<<rate<<endl;}

	cout<<"The Amount Due Is: "<<amount<<endl;
}

i did this it finishes compiling without errors but their a runtime error
Code:
warning C4700: uninitialized local variable 'hours' used warning C4700: uninitialized local variable 'rate' used warning C4700: uninitialized local variable 'amount' used
Last edited by admin : 11-Nov-2009 at 04:27. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #5  
Old 10-Nov-2009, 08:29
abdaalh abdaalh is offline
New Member
 
Join Date: Nov 2009
Posts: 4
abdaalh is on a distinguished road

Re: Write function getHoursRate that asks to inp the inp variables to initiliaze in m


CPP / C++ / C Code:
#include <iostream>
using namespace std;
void getHoursRate ();
void paycheck(double rate, double hour);
void printCheck(double rate, double hours, double amount);

void main(double rate, double hours, double amount)
{
	getHoursRate();
	paycheck(rate, hours);
	printCheck(rate, hours, amount);
}

void getHoursRate ()
{
	double rate;
	double hours;

	cout<<"Enter Number Of Hours Worked: ";
	cin>>hours;
	cout<<"Enter Rate Per Hour: ";
	cin>>rate;
}

void paycheck(double rate, double hours)
{
	double amount;

	if (0<=hours && hours<=40)
		{amount = rate * hours;
		cout<<"\nThe Amount Due Is: "<<set.precision(10)<<amount<<endl;}
	else
		{amount = rate * 1.5 * hours;
		cout<<"\nThe Amount Due Is: "<<set.precision(10)<<amount<<endl;}
}

void printCheck(double rate, double hours, double amount)
{
	cout<<"\nThe Number Of Hours Is: "<<hours;

	if (0<=hours && hours<=40)
		{rate = rate;
		cout<<"The Rate Is: "<<set.precision(10)<<rate<<endl;}
	else
		{rate = 1.5 * rate;
		cout<<"The Rate Is: "<<set.precision(10)<<rate<<endl;}

	cout<<"The Amount Due Is: "<<set.precision(10)<<amount<<endl;
}

I'v Also Tried this which works but this time it returns wrong answers
Last edited by admin : 11-Nov-2009 at 04:28. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #6  
Old 10-Nov-2009, 08:30
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 815
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Write function getHoursRate that asks to inp the inp variables to initiliaze in main


Read my previous post. You must either pass by reference or pass the pointer in. Otherwise, your variables will never be filled with meaningful values. See this for more information. Also, when posting code, use CPP tags around it.
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free a malloc returned in a function james_bond C Programming Language 4 06-Jan-2008 13:59
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38
How to write output with a function jenmaz C Programming Language 8 17-Nov-2004 23:01
Another problem dealing with main() and driver function tommy69 C Programming Language 4 20-Mar-2004 19:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:53.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.