Question:

A parking garage charges RM 0.50 per minute fee. Write a program that prompts user to input the number of hours and minutes parked. The program will then calculate and display the total minutes parked and the charges to be paid by customer based on the basic fee given. If the charges is greater than RM80.00, discount 10% is given to the customer.

#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

double calculateCharge(double a, double b);
int main()

double num=0;
double num1=0;
double total=0;
cout<<"\t\t********************************************************"<<endl;
cout<<"\t\t\t Welcome to parking garage system"<<endl;
cout<<"\t\t********************************************************"<<endl<<endl<<endl;

cout<<"\t\tPlease enter first customer's hours parked:";
cin>>num;
cout<<"\t\tPlease enter first customer's minutes parked:";
cin>>num1;
cout<<endl<<endl;
cout<<"\t*****************************************************************"<<endl<<endl<<endl;
cout<<setw(5) << "Car" << setw(12) << "Hours" <<setw(12) "Minutes" << setw(16) << "Charge"
<< endl;

cout << setw(5) << num << setw(14) << num1 <<setw(16) << fixed << setprecision(2)
<< calculateCharge (num, num1) << endl;

total = ( calculateCharge (num, num1) );
cout<<setw(5) << "TOTAL" << setw(14) << num << setw(16) << fixed <<
setprecision(2) << total
<< endl;

system("pause");
return 0;
}//end main

double calculateCharge(double x, double y)
{
double charge;

if ( (x <= 2) && (y >= 40) )
charge = ( (x * 30) + (y * 0.5) );

else if ( (x > 2) && (y > 40) )
charge = ((x * 30) + (y * 0.5) );

return charge;

}

your main has no opening bracket "{"
oh ok thanks..how about the full coding.. i can't run this prog by visual basic c++ 2008
I will not write the whole code for you.
oh ok..
Can you edit your main post and add the code tags? You just need to select all the code and while it's selected press the <> button on the right (It should be the topleft button)
ok i'll do it
 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include #include #include using namespace std; double calculateCharge(double a, double b); int main() { double num=0; double num1=0; double total=0; cout<<"\t\t********************************************************"<>num; cout<<"\t\tPlease enter first customer's minutes parked:"; cin>>num1; cout<
Last edited on
 ``12345678910111213`` ``````double calculateCharge(double x, double y) { double charge; if ( (x <= 2) && (y >= 40) ) charge = ( (x * 30) + (y * 0.5) ); else if ( (x > 2) && (y > 40) ) charge = ((x * 30) + (y * 0.5) ); return charge; }``````

x = hours
y = minutes
Ok, but, what is the problem? What's not working? (I'm going to test this program right now huh) The only thing I can tell you right now that can help you is this:

 ``12345`` ``````double calculateCharge(double x, double y) { // double charge; ---> this variable is not initialized. Under certain circumstances // you may end up with an unknown return value. So initialize this to 0.0: double charge = 0.0;``````

Also here you have a mistake on line 25:
 `` `` ``...<

Also, did you write the following things because your teachers did teach you?

I mean these:
 ``12345`` ``````// beginning: #include // ending of main() system("pause");``````

If your teacher teached you these two things, you are probably having a bad teacher.
in C++ you should do such things differently:

 ``1234567`` ``````// beginning: remove "#include " and add: #include // ending of main(): remove system("pause") and add: cout<<"\nPress a Key to Exit."; cin.ignore(numeric_limits::max(), '\n'); cin.get();``````

The first thing, about including cmath, isn't really important because of something, but, as you are on C++, you shouldn't use C headers.

math.h is C, cmath is C++.
the system() thing is a REALLY important thing. It is REALLY risky and you should NEVER, NEVER use it. It also "flags" your executable as a virus.