Click here to Skip to main content
15,900,254 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Enums Pin
Maxwell Chen24-Mar-04 21:52
Maxwell Chen24-Mar-04 21:52 
GeneralRe: Enums Pin
David Crow25-Mar-04 2:48
David Crow25-Mar-04 2:48 
GeneralRe: Enums Pin
monrobot1325-Mar-04 18:33
monrobot1325-Mar-04 18:33 
Generalimproving a hack Pin
axid3j1al24-Mar-04 20:25
axid3j1al24-Mar-04 20:25 
QuestionHow to popup the application-menu ? Pin
ohadp24-Mar-04 20:16
ohadp24-Mar-04 20:16 
GeneralError in calling DLL Pin
dafan24-Mar-04 19:14
dafan24-Mar-04 19:14 
GeneralRe: Error in calling DLL Pin
dafan25-Mar-04 2:41
dafan25-Mar-04 2:41 
GeneralA Loop...homework tips please! Pin
Joe Estes24-Mar-04 18:27
Joe Estes24-Mar-04 18:27 
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..

Enter car type...C T or S...or press x to exit program..(not exactly say that...) but if you enter c t or s , it will then ask for miles which it does, then it calculates them. But when its done, I want it to keep asking for a new type of car., Then miles...and then calculate all the same stuff all over again Then when I've decided i want to end the program after trying,( say all the different types of cars and different minute variations,

..i would simple type in x, and then enter, and it would end the loop and the program will close.

Hope that helps


void getInput() <br />
{ <br />
 <br />
 char vType;<br />
 <br />
 cout << "Enter the type of car"; <br />
 cout << endl; <br />
 cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: "; <br />
 cout << endl;  <br />
 cout << "Press X to exit program : ";<br />
 cin  >> vType; <br />
 cout << endl; <br />
 if (tolower(vType) == 'x') <br />
         { <br />
  return; <br />
          } <br />
 cout <<"Enter the number of minutes the vehicle has been parked: "; <br />
 cin  >> mtime; <br />
  <br />
 computePrice(vType,mtime); <br />
} <br />
int main() <br />
{ <br />
 getInput(); <br />
  <br />
 cin.ignore(); <br />
 cin.get(); <br />
  <br />
 return 0; <br />
} 


and heres the full beautiful thing...

 // Program 4 CSC140-001  3/15/04 <br />
//A program which prints tickets given an amount of time a car has been parked. <br />
//Will read from file a list of various cars and times. <br />
<br />
#include <iostream>  <br />
#include <fstream> <br />
#include <string> <br />
<br />
using namespace std; <br />
<br />
int mtime; <br />
<br />
void printTicket(char vType, int minutes, double p, int hours) <br />
{ <br />
  <br />
<br />
 string carType; <br />
 if(vType == 'c'){ <br />
  carType = "Car"; <br />
 } <br />
 else if(vType == 't'){ <br />
  carType = "Truck"; <br />
 } <br />
 else if(vType == 's'){ <br />
  carType = "Senior"; <br />
 } <br />
 cout<<" PENTAGON VISITOR PARKING" << endl; <br />
  cout<<"       Type ..... " << carType << endl; <br />
  cout<<"       Minutes .. " << minutes<< endl; <br />
  cout<<"       Hours .... " << hours << endl; <br />
  cout<<"       Charge ... " << p << endl; <br />
} <br />
  <br />
  <br />
void computePrice(char vType, int time) <br />
{ <br />
 vType = tolower(vType); <br />
<br />
 double p = 0.0; <br />
  //int  h = time/60.0; <br />
 double h = time/60;<br />
 if(time%60 > 0.0) <br />
  h++ ; <br />
 if(vType == 'c'){ <br />
  if(time <= 120){ <br />
    p = 0.00; <br />
   } <br />
   else if(time > 120 && time <= 300){ <br />
    p = .50*(h-2.00); <br />
   } <br />
   else if(time >300){ <br />
    p = .25*(h-5)+1.5; <br />
   } <br />
  } <br />
 else if(vType == 't'){ <br />
  if(time <= 60){ <br />
   p = 0.00; <br />
  } <br />
  else if(time > 60 && time <=180){ <br />
   p = 1.00*(h-1.00); <br />
  } <br />
  else if(time > 180){ <br />
   p = .75*(h-3)+2.00; <br />
  } <br />
 } <br />
  else if(vType == 's') <br />
   p = 0.00; <br />
<br />
 printTicket(vType,time,p,h); <br />
} <br />
<br />
<br />
void getInput() <br />
{ <br />
 <br />
 char vType;<br />
 <br />
 <br />
 cout << "Enter the type of car"; <br />
 cout << endl; <br />
 cout << "(e.g. 'C' for car, 'T' for truck, or 'S' for senior citizen: "; <br />
 cout << endl;  <br />
 cout << "Press X to exit program : ";<br />
 cin  >> vType; <br />
 cout << endl; <br />
 if (tolower(vType) == 'x') <br />
 { <br />
  return; <br />
} <br />
 cout <<"Enter the number of minutes the vehicle has been parked: "; <br />
 cin  >> mtime; <br />
  <br />
 computePrice(vType,mtime); <br />
} <br />
int main() <br />
{ <br />
<br />
 getInput(); <br />
  <br />
 cin.ignore(); <br />
 cin.get(); <br />
  <br />
 return 0; <br />
}


thanks again!
GeneralRe: A Loop...homework tips please! Pin
Roger Wright24-Mar-04 19:54
professionalRoger Wright24-Mar-04 19:54 
GeneralRe: A Loop...homework tips please! Pin
Prakash Nadar24-Mar-04 20:16
Prakash Nadar24-Mar-04 20:16 
GeneralRe: A Loop...homework tips please! Pin
Roger Wright24-Mar-04 20:46
professionalRoger Wright24-Mar-04 20:46 
GeneralRe: A Loop...homework tips please! Pin
Prakash Nadar24-Mar-04 20:54
Prakash Nadar24-Mar-04 20:54 
GeneralRe: A Loop...homework tips please! Pin
Roger Wright24-Mar-04 21:00
professionalRoger Wright24-Mar-04 21:00 
GeneralRe: A Loop...homework tips please! Pin
peterzorbas24-Mar-04 21:40
peterzorbas24-Mar-04 21:40 
GeneralRe: A Loop...homework tips please! Pin
peterzorbas24-Mar-04 21:58
peterzorbas24-Mar-04 21:58 
GeneralRe: A Loop...homework tips please! Pin
peterzorbas24-Mar-04 21:57
peterzorbas24-Mar-04 21:57 
GeneralRe: A Loop...homework tips please! Pin
Paul Ranson25-Mar-04 2:35
Paul Ranson25-Mar-04 2:35 
GeneralRe: A Loop...homework tips please! Pin
Roger Wright25-Mar-04 5:55
professionalRoger Wright25-Mar-04 5:55 
GeneralRe: A Loop...homework tips please! Pin
Paul Ranson25-Mar-04 6:42
Paul Ranson25-Mar-04 6:42 
GeneralRe: A Loop...homework tips please! Pin
Roger Wright25-Mar-04 7:59
professionalRoger Wright25-Mar-04 7:59 
GeneralRe: A Loop...homework tips please! Pin
Maxwell Chen25-Mar-04 16:55
Maxwell Chen25-Mar-04 16:55 
Generalsave application Pin
archanagaby24-Mar-04 17:44
archanagaby24-Mar-04 17:44 
GeneralRe: save application Pin
David Crow25-Mar-04 8:59
David Crow25-Mar-04 8:59 
GeneralSplit CString Pin
Simon Poon24-Mar-04 15:45
Simon Poon24-Mar-04 15:45 
GeneralRe: Split CString Pin
David Salter24-Mar-04 22:14
David Salter24-Mar-04 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.