how to change it??>Parking charge given is from 6am to 6pm. If after 6pm until 6am, per entry parking charges is RM 6.00.

#include <iostream>
using namespace std;
int main ()
{
int hours,charges,total,vehicles;
int first = 3;
int second = 2;
int subsequent = 1;
total = 0 ;
vehicles = 0;
cout <<"Input parking hours: ";
cin >> hours;
while (hours > 0)
{
if (hours <= 12)
{
if (hours == 1)
charges = first;
else if (hours == 2)
charges = first +second;
else charges = first + second + (hours-2)*subsequent;
cout <<"Packing charges is RM "<< charges << endl;
cout << endl;
total * total + charges;
vehicles = vehicles + 1;
}
else cout << "ERROR in INPUT ==> Maximum hours is 12" << endl;
cout <<"Input packing hours: ";
cin >> hours;
}
cout <<"Number of vehicles: "<< vehicles << endl;
cout <<"Total collection for the day: " << total << endl;
return 0;
}
You do need two pieces of data from the user: start-time and duration. Now you only ask for duration. With start-time you can calculate how much is in the day and how much in the night.
so many syntax error!!! Can't..really dun know how
1) Please use code tags when posting code here, to make it readable.

2) We're not interested in silly guessing games. If you you have a problem, tell us what it is. If you're getting error messages, tell us what they are and where they are. What possible reason could you have for withholding this information, unless it's to jerk us around?
any good suggestion better 1?
#include <iostream>
using namespace std;
int main ()
{
int hours,charges,total,vehicles,time;
int first = 3;
int second = 2;
int subsequent = 1;
vehicles = 0;
total = 0;
charges = 0;

cout <<"Input parking hours: ";
cin >> hours;
cout << endl;
cout <<"Input parking time:";
cin >> time;
cout << endl;

while (hours > 0)
{
if (hours <= 12)
{
if (((time >18) && (time <= 24)) || ((time >= 1) && (time <= 6)))
{
charges = 6;

}
else if ((time > 6) || (time <= 18))
{
if (hours == 1)
charges = first;
else if (hours == 2)
charges = first +second;
else charges = first + second + (hours-2)*subsequent;
}

cout <<"Packing charges is RM "<< charges << endl;
cout << endl;
total = total + charges;
vehicles = vehicles + 1;
}
else cout << "ERROR in INPUT ==> Maximum hours is 12" << endl;
cout <<"Input parking hours: ";
cin >> hours;
cout <<endl;
cout <<"Input parking time:";
cin >> time;
cout << endl;
}
cout <<"Number of vehicles: "<< vehicles << endl;
cout <<"Total collection for the day: " << total << endl;
return 0;
}
any good suggestion better 1?


I have two very good suggestions:

1) Use code tags when posting, so that we can read your code easily.

2) Tell us clearly what your problem is, and what errors you're getting.

Hmm, I'm getting a strange sense of deja vu...
sorry newbie here..Not really how to use it..
If I write as above still got the logical problem?
or got any code better for suggestion?
sorry for my poor English!
Suggestion 1 is explained here: http://www.cplusplus.com/forum/articles/42672/

The result will look like:
1
2
3
4
5
6
7
8
9
10
if ( ((time >18) && (time <= 24)) || ((time >= 1) && (time <= 6)) )
{
  charges = 6;
}
else if ( (time > 6) || (time <= 18) )
{
  if (hours == 1) charges = first;
  else if (hours == 2) charges = first +second;
  else charges = first + second + (hours-2)*subsequent;
}

What is the purpose of the if-condition on line 5? Oh, wait, I know: the user loves to park at -7 o'clock. But if so, then he should be instructed to use standard time.

How do you take into account that I did park my car at 17:00, spending only the first hour within the 6-18 period? How could you calculate it?
Topic archived. No new replies allowed.