Parking Fee question

Could you help with an error I am getting with the IF(totalMinutes==0). I need to have a error message stating that 0 is not acceptable.

#include <cstdlib>

#include <iomanip>

#include <iostream>
using namespace std;

/**************************** main Function **************************/
int main()

{
float parkingFee;
int totalMinutes, hoursParked, minutesParked;

//Get the total minutes parked and check to make sure the input is not zero
cout<<"Enter total minutes parked:"<<endl;
cin>>totalMinutes;
IF(totalMinutes==0)
cout<<"You have not entered a valid number"<<endl;

//If minutes is not zero, compute hours & minutes
hoursParked=totalMinutes/60
minutesParked=totalMinutes%60

//Compute the parking fee for total # of hours parked
parkingFee=hoursParked*1.00

//If there are any left over minutes and a dollar to parking fee
parkingFee=parkingFee+1.00

//Display total hours, minutes and parking fee.
cout<<fixed<<showpoint<<setprecision(2);
cout<<"The total time parked is:"<<hoursParked<<"hours"<<minutesParked<<"minutes"<<endl;
cout<<"The total parking fee is:"<<parkingFee<<endl;

system ("pause");
return 0;
}


Thanks in advance for your help.
Text in the compiler is case sensitive and "IF" is not valid but "if" is. You may want a loop to make sure that totalMinutes contains a valid number before moving on to calculations:

1
2
3
4
5
6
7
8
9
10
  cout << "Enter total minutes parked:" << endl;
  cin >> totalMinutes;
  while(totalMinutes<=0) // wouldn't want negative or 0
  {
    cout<<"You have not entered a valid number!"<<endl;
    cout << "Please enter total minutes parked: ";
    cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); // flush chars out of cin buffer
    cin.clear(); // reset cin error flags
    cin >> totalMinutes;
  }
Thank you.
Any tips on the breakdown from total minutes to hours and minutes?

1
2
hoursParked=totalMinutes/60
    minutesParked=totalMinutes%60
Topic archived. No new replies allowed.