Oct 18, 2012 at 4:29pm UTC
Hello everybody I am a noob and need help with my program.
The function names and variables are given in my assignment and cannot be changed.
I get zero zero zero for output, not sure why...
Heres my code:
#include <iostream>
using namespace std;
double getHoursRate ( double hours , double rate ) ;
double payCheck ( double hours , double rate ) ;
double Printcheck ( double hours , double rate , double ammount ) ;
int main ()
{
double rate=0;
double hours=0;
double ammount=0;
getHoursRate ( hours , rate ) ;
payCheck ( hours , rate ) ;
Printcheck ( hours , rate , ammount ) ;
system ( " pause " );
}
double getHoursRate (double hours , double rate)
{
cout << "Please enter the number of hours worked " << endl;
cin >> hours ;
cout << "Please enter the rate of wage now " << endl;
cin >> rate;
return hours , rate ;
}
double payCheck (double hours , double rate )
{
double ammount =0 ;
double overpay =0 ;
if ( hours <= 40 )
{
ammount = hours * rate;
}
else
overpay= hours - 40;
ammount = (40 * rate ) + ( overpay * (rate * 1.5 ) ) ;
return ammount ;
}
double Printcheck ( double hours , double rate , double ammount )
{
cout << " You/employee has worked " << hours << endl;
cout << " Yours/employee's rate is " << rate << endl;
cout << " Your/employee's salary is " << ammount << endl;
return (0);
}
Last edited on Oct 18, 2012 at 7:11pm UTC
Oct 18, 2012 at 4:32pm UTC
When the compiler analyzes these statements
1 2 3 4 5 6 7
rate = getHoursRate ( hours , rate ) ;
hours = getHoursRate ( hours , rate ) ;
ammount= payCheck ( hours , rate ) ;
Printcheck ( hours , rate , ammount ) ;
it does not know where these names as getHoursRate and others are declared. Any name that is used in a program shall be
at first declared .
Last edited on Oct 18, 2012 at 4:32pm UTC
Oct 18, 2012 at 4:32pm UTC
When you have an error message, it helps us a lot to know what the error message is.
The problem is that you are trying to use functions getHoursRate, payCheck and Printcheck before you have told the compiler about them.
The compiler starts at the top. It comes to the line
rate = getHoursRate ( hours , rate ) ;
and at this point it has never heard of the function getHoursRate, so it doesn't know what to do and stops. Similarly for the other functions.
Either
1) Declare the functions before you use them, or
2) Define the functions before you use them.
Oct 18, 2012 at 6:11pm UTC
Thank you Moschops and vlad for answers.
I have changed my code , i understand decleration now. But i get zero from print. Please help me understand why.
#include <iostream>
using namespace std;
double getHoursRate ( double hours , double rate ) ;
double payCheck ( double hours , double rate ) ;
double Printcheck ( double hours , double rate , double ammount ) ;
int main ()
{
double rate=0;
double hours=0;
double ammount=0;
getHoursRate ( hours , rate ) ;
payCheck ( hours , rate ) ;
Printcheck ( hours , rate , ammount ) ;
system ( " pause " );
}
double getHoursRate (double hours , double rate)
{
cout << "Please enter the number of hours worked " << endl;
cin >> hours ;
cout << "Please enter the rate of wage now " << endl;
cin >> rate;
return hours , rate ;
}
double payCheck (double hours , double rate )
{
double ammount =0 ;
double overpay =0 ;
if ( hours <= 40 )
{
ammount = hours * rate;
}
else
overpay= hours - 40;
ammount = (40 * rate ) + ( overpay * (rate * 1.5 ) ) ;
return ammount ;
}
double Printcheck ( double hours , double rate , double ammount )
{
cout << " You/employee has worked " << hours << endl;
cout << " Yours/employee's rate is " << rate << endl;
cout << " Your/employee's salary is " << ammount << endl;
return (0);
}
Last edited on Oct 18, 2012 at 6:19pm UTC