#include <iostream>


using namespace std;

int main ()

    int charge, aftercharge, parking_hours;

     cout << "please put your parking hours:    " ;
     cin >> parking_hours;

     if (parking_hours>=1)
     {
        charge = 1 ;
     }
     else if (parking_hours>=11)
    {
        charge = 2.50 ;
    }
     else if (parking_hours>=12)
     {
        charge = 6.00 ;

     }
     aftercharge = parking_hours*charge ;

     cout << "your bills RM" << aftercharge;
     cout << "this is your charge RM: " << parking_hours;

return 0;

hey pls answer my question

Let's work through this if statement ...

Let's assume that the parking_hours is 15.

On line 13, we say if parking_hours is more than or equal to 1, do this ...

Well, 15 is definitely more than or equal to 1. So we set charge = 1 and then we continue on to line 26.

Something tells me that isn't what you want to have happen.

You need to reverse your conditionals, starting from the highest and working your way down, as so:

if (parking_hours>=12)
 {
    charge = 1 ;
 }
 else if (parking_hours>=11)
{
    charge = 2.50 ;
}
else if (parking_hours>=1)
 {
    charge = 6 ;
 }

You'll notice that I have also reversed the value of charge with each conditional. I'm assuming what you mean to do is that the more hours you park, the cheaper the hourly rate gets. Therefore, if you are parked for 15 hours, you'll hit true for it being >= 12, and be charged 1 per hour. If you're parked for 5 hours, you'll hit false for it being >= 12, then continue on and hit false for it being >= 11, then continue on and hit true for it being >= 1, and be charged 6 per hour.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.