I am having a problem getting the execution screen to stay in order for me to view the program. Can someone tell me what is wrong with my program please?

//

/*
A parking garage charges a \$2.00 miniumum fee to pack for up to three hours.
The garage charges an additional \$0.50 per hour for each hour or part thereof
in excess of three hours. The maximum charge for any given 24-hour period is \$10.00.
Assume that no car parks for longer than 24 hours at a time. Write a program that
calculates and prints the parking charges for each of three customers who parked
their cars in this garage yesterday. You should enter the hours parked for each customer.
Your program should print the results in a neat tubular format and should calculate
and print the total of yesterday’s receipts. The program should A parking garage charges
a \$2.00 miniumum fee to pack for up to three hours. The garage charges an additional
\$0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge
for any given 24-hour period is \$10.00. Assume that no car parks for longer than 24 hours
at a time. Write a program that calculates and prints the parking charges for each of
three customers who parked their cars in this garage yesterday. You should enter the hours
parked for each customer. Your program should print the results in a neat tubular format
and should calculate and print the total of yesterday’s receipts. The program should use
the function calculateCharges to determine the charge for each customer.

*/

``````#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::fixed;

#include <iomanip>

using std::setprecision;

const int CARS = 3;//number of cars parked yesterday

//function used to calculate parking charges
double calculateCharges(double hours)
{
double charge;

// charge minnimum rate of 2 dollars for 3 hours
if (hours<=3)
{
charge=2;
}

// hours > 3
else
{
charge=2;   // charge base rate of 2 dollars
hours-=3;   // check how long over 3 hours the car was parked
while(hours>0)
{
charge+=.5; // charge 50 cents for extra hours
hours--;    // hour or part of was charged
}
}

if (charge>10) // flat rate of 10 dollars is charged
charge=10;
return charge;
}

int main()
{
double hours[CARS];                 // store hours parked by the different cars
double thours=0, tcharge=0, charge; // stores daily totals and total for a car
int i;

cout << "Parking Garage" << endl;

// get hours parked
for(i=0; i<CARS;i++)
{
cout << "How long was car " <<(i+1)<<" parked? ";
cin >> hours;
}

cout << endl;
cout << "Car\tHours\tCharge" << endl;

// for each car
for(i=0;i<CARS;i++)
{
// get amount owed
charge = calculateCharges (hours);

// display charges

// car
cout << (i+1);

// hours
cout << setprecision ( 1 );
cout << hours;

// charges
cout << setprecision ( 2 );
cout << charge << endl;

thours+=hours;
tcharge+=charge;
}

// print totals
cout << "Total" << thours << tcharge << endl;

return 0;
}
``````

## All 11 Replies

I am having a problem getting the execution screen to stay in order for me to view the program. Can someone tell me what is wrong with my program please?

Nothing is "wrong".

there is an even better way to do that.

after you compile the program for the first time, find the exe it creates. Right click the exe, click properties, click the program tab, uncheck the box "close on exit". then click apply!

turning that off will leave the DOS window open until you close it. This is better because you can recompile the program and rerun the program from within the editor with out having to find the file every time :-p.

there is an even better way to do that.

after you compile the program for the first time, find the exe it creates. Right click the exe, click properties, click the program tab, uncheck the box "close on exit". then click apply!

turning that off will leave the DOS window open until you close it. This is better because you can recompile the program and rerun the program from within the editor with out having to find the file every time :-p.

Thanks for that tip, I will try it out.

Sukiebaby ;)

are you using DEV c++

good tip binary mayhen i never new you could do that. i will have to look into that :)

Hi.

That's the problem with not specifying the operating system you are compiling under. My linux box had no problem with it.

Enjoy,

Christian

yeah me to but i just assumed that this was windows being talked about :)

Excellent !
You have saved, a countless number of tangent pressing occasions !

Mayhem i never knew about that either. that saves a lot of confusion and time. ;/

there is an even better way to do that.

after you compile the program for the first time, find the exe it creates. Right click the exe, click properties, click the program tab, uncheck the box "close on exit". then click apply!

turning that off will leave the DOS window open until you close it. This is better because you can recompile the program and rerun the program from within the editor with out having to find the file every time :-p.

Your instructions don't apply to my Windows box (Windows XP Professional, SP1). Not only is there no "close on exit" box, there's no program tab in the properties menu of the executable. Any ideas?

there is another way too. whenever you want the program to pause so the user can read what it says you can type in getch(); and it will pause the program until the user presses anykey. (usefull for when you wish to display multiple pages of information.)
for example:

``````#include <iostream.h>
#include <conio.h>
int main()
{
cout << "press any key to continue..." << endl;
getch();
return 0;
}``````

will pause the screen while saying press anykey to continue until the user presses anykey. (in this example the window would close after you press anykey.).

(p.s. sorry for the long explination of getch () (which you probobly knew of already) but i wanted to make sure you understood what i ment, i hate it when people would just say something like "use the getch command" lol)

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.