Alright, thank you ahead of time.
First off here is what the program is supposed to do, what i am having trouble with is in bold..
"Write a program that will accept as input a one character desinator (C,T,S) followed by the number of minutes a vehicle has been in the lot. THe program should then compute the appropriate charge and print a ticket for the custormer. Any part of an hour is to be counted as a full hour. At a later time the program should be modified to loop until the character "x" is entered for input. Use functions as needed! "
Alright this is my problem, the program displays correctly and executes and all that , BUT I just don't know how to do the loop... i think it has to be a while loop ...
I know what it should say in english, I think ...
It should keep asking for C,T, S and the number of minutes..infinitely until I input an "X"..but I dont know how to translate that into code.. here is where I "think" it has to go, but my full program is under it..
Code:
void getInput()
{
char vType;
cout << "Enter the type of car";
cout << endl;
cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: ";
cout << endl;
cout << "Press X to exit program : ";
cin >> vType;
cout << endl;
if (tolower(vType) == 'x')
{
return;
}
cout <<"Enter the number of minutes the vehicle has been parked: ";
cin >> mtime;
computePrice(vType,mtime);
}
int main()
{
getInput();
cin.ignore();
cin.get();
return 0;
}
and heres the full beautiful thing...
Code:
// Program 4 CSC140-001 3/15/04
//A program which prints tickets given an amount of time a car has been parked.
//Will read from file a list of various cars and times.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int mtime;
void printTicket(char vType, int minutes, double p, int hours)
{
string carType;
if(vType == 'c'){
carType = "Car";
}
else if(vType == 't'){
carType = "Truck";
}
else if(vType == 's'){
carType = "Senior";
}
cout<<" PENTAGON VISITOR PARKING" << endl;
cout<<" Type ..... " << carType << endl;
cout<<" Minutes .. " << minutes<< endl;
cout<<" Hours .... " << hours << endl;
cout<<" Charge ... " << p << endl;
}
void computePrice(char vType, int time)
{
vType = tolower(vType);
double p = 0.0;
//int h = time/60.0;
double h = time/60;
if(time%60 > 0.0)
h++ ;
if(vType == 'c'){
if(time <= 120){
p = 0.00;
}
else if(time > 120 && time <= 300){
p = .50*(h-2.00);
}
else if(time >300){
p = .25*(h-5)+1.5;
}
}
else if(vType == 't'){
if(time <= 60){
p = 0.00;
}
else if(time > 60 && time <=180){
p = 1.00*(h-1.00);
}
else if(time > 180){
p = .75*(h-3)+2.00;
}
}
else if(vType == 's')
p = 0.00;
printTicket(vType,time,p,h);
}
void getInput()
{
char vType;
cout << "Enter the type of car";
cout << endl;
cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: ";
cout << endl;
cout << "Press X to exit program : ";
cin >> vType;
cout << endl;
if (tolower(vType) == 'x')
{
return;
}
cout <<"Enter the number of minutes the vehicle has been parked: ";
cin >> mtime;
computePrice(vType,mtime);
}
int main()
{
getInput();
cin.ignore();
cin.get();
return 0;
}
thanks again!