954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't see the program execute

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

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

#include

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> hours[i];
}

//print header
cout << endl;
cout << "Car\tHours\tCharge" << endl;

// for each car
for(i=0;i

Sukiebaby
Newbie Poster
3 posts since Jun 2004
Reputation Points: 10
Solved Threads: 0
 
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". http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043803465&id=1043284385

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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.

BinaryMayhem
Junior Poster
176 posts since Jun 2004
Reputation Points: 15
Solved Threads: 10
 

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 ;)

Sukiebaby
Newbie Poster
3 posts since Jun 2004
Reputation Points: 10
Solved Threads: 0
 

are you using DEV c++

marceta
Posting Whiz in Training
217 posts since May 2004
Reputation Points: 13
Solved Threads: 0
 

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

big_k105
PFO Founder
Team Colleague
357 posts since May 2003
Reputation Points: 36
Solved Threads: 2
 

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

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

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

big_k105
PFO Founder
Team Colleague
357 posts since May 2003
Reputation Points: 36
Solved Threads: 2
 

Excellent !
You have saved, a countless number of tangent pressing occasions !
Which are to many already.

bosk
Newbie Poster
1 post since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

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

bombe
Newbie Poster
14 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

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?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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)

evilsilver
Junior Poster in Training
84 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You