Saturday, May 22, 2010

Need some C++ help?

int main ( )


{


int loopCount;


loopCount = 1;


while (loopCount != X)


{


cout%26lt;%26lt;" Enter (C)ar, (T)ruck, (S)enior Citizen, or E(X)it: ";


cin%26gt;%26gt; type;








cout%26lt;%26lt;endl%26lt;%26lt;endl;





cout%26lt;%26lt;"How Many Minutes Parked: ";


cin%26gt;%26gt; minutes ;








cout%26lt;%26lt;endl%26lt;%26lt;endl;





cout%26lt;%26lt;" PENTAGON VISITOR PARKING"%26lt;%26lt;endl%26lt;%26lt;endl;





cout%26lt;%26lt;" Type....."%26lt;%26lt; " ";


if(type == 'C') {


cout%26lt;%26lt;"Car";


}


if (type == 'T'){


cout%26lt;%26lt;"Truck";


}


if (type == 'S'){


cout%26lt;%26lt;"Senior";


}





This is what I have right now, but I want to hit X, and it to exite the program. Any takers??????

Need some C++ help?
several methods can be used:





Method #1:








main(){


int still=1;


//your code goes here





while(still==1){





//your code goes here





if(type=='X'){


still=0;


}





}





}








Method#2:


main(){





//your code goes here





while(1){








//your code goes here





if(type=='X'){


goto fin;


}





}





fin:








}











Note: fin is user defined, and it is after the while loop, so that when X is input it will go to fin and then exit.











you can use function getch() instead of cin, because getch() gets only one character and does not need an enter key to be pressed.








you can have a code like:





while(type=getch()!='x'){





//your code goes here to take action from type








}








Here is a complete solution(copy, paste, run):





# include %26lt;stdio.h%26gt;


# include %26lt;conio.h%26gt;





main(){


char type;





printf(" Enter (C)ar, (T)ruck, (S)enior Citizen, or E(X)it: \n");





while (((type=getch())!='x') %26amp;%26amp; (type!='X')){





if (type=='c' || type=='C')


printf("Car\n");


if (type=='t' || type=='T')


printf("Truck\n");


if (type=='s' || type=='S')


printf("Senior Citizen\n");








}
Reply:For getting homework help there are better websites like http://getafreelnacer.com/
Reply:i sense HOME WORK question...





BIG clue is





if(type == '?')





you bypass the rest of the functions and exit, instead of doing the calculation.
Reply:Why do you need "loopCount"? Just make "type" a char, and initialize it to a blank (' ') before the loop. Change the while statement to type != 'X'.


No comments:

Post a Comment