| | |
PLZ help me !!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 1
Reputation:
Solved Threads: 0
I have to submit the assignment tomorrow i got stuck in something looks silly the question is:
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.
and my solution is
C++ Syntax (Toggle Plain Text)
//Hours and Charges for three cars which parked yesterday #include <iostream> using std::cout; using std::cin; using std::endl; using std::fixed; #include <iomanip>//parameterized stream manipulators using std::setw;//The output appears in a field width of 10 using std::setprecision; //sets numeric output precision int main() { double TotalHours, //using the double to use the variables with decimal points a, hr1,hr2,hr3, charge, calculateCharges; //Intialization phase calculateCharges=0; //Processing phase cout<< "Enter the hours parked for three cars : ";//prompt for input cin >> hr1 >> hr2 >> hr3;//input the hour of each of the three cars cout<< setw(5)<< "Car" << setw(10)<< "Hours" << setw(15)<< "Charges\n\n"; cout<<fixed<<setprecision(2); //sets numeric output precision for(int counter=1;counter<=3;counter++) {//loop 3 times and in every loop the counter is incremented by 1 if (counter == 1) a = hr1; else if (counter == 2) a = hr2; else if (counter == 3) a = hr3; if (a <= 3) charge = 2; else if (a >19) charge = 10; else if (a > 3) charge = 2 + (a - 3) * (0.5); cout <<setw(5) << counter<< setw(10) <<setprecision(2)<< a << setw(10)<< charge <<"\n\n"; calculateCharges+=charge;//in every loop the Sum of the charges is incremented according to the value of the charge } //Termination phase TotalHours=hr1+hr2+hr3;//It gives the total of the hours parked for three cars cout<<" "<<"Total"<<setw(7)<<TotalHours<<setw(10)<<calculateCharges<<"\n\n"<<endl; return 0; //successful termination }
the problem that when the time is shown it has to be only with one decimal point not to decimal points for example if it is 2.40 i need it to be 2.4
Help me plz
![]() |
Similar Threads
- can someone plz help me with this? (Visual Basic 4 / 5 / 6)
- I NEED SUPPORT **"IMPORTANT"** PLZ HELP (Windows NT / 2000 / XP)
- Windows media player (Windows NT / 2000 / XP)
- Bridge.dll...Make it go away, Plz (Viruses, Spyware and other Nasties)
- can sum1 look @ dis plz (Viruses, Spyware and other Nasties)
- Hijackthis log file - plz help (Viruses, Spyware and other Nasties)
- IE not working...PLZ help :cry: (Web Browsers)
- PLZ help it's urgent! (Web Browsers)
- plz help ppl...... (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: How to read Matlab Variabls in C++
- Next Thread: Export Obejct from DLL
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






