Re: noob Dev-C++ help. Need to calc area & perimeter of a rectangle (class proj).
I'm having a new problem with a new program. The program is called Tollbooth and the design is to have it where the program asks the user to pay a toll based on the vehicle they drive. And the user would input a single letter, like M for Motorcycle, then the program would output the amount owed for the toll. But my problem is, no matter the letter that is entered, it lists all the toll prices. Here is what I have for the program so far. Any thoughts that would lead me to figuring out what im doing wrong is greatly appreciated!
Re: noob Dev-C++ help. Need to calc area & perimeter of a rectangle (class proj).
And what exactly does = do, and what should you be using instead to test for equality?
Why are you using a double to hold alpha data?
What are all those other unitialized doubles supposed to be doing?
If you want somebody to enter an alpha character, your data type should be a char, and you should be testing for equality against character literals, not unitialized doubles.
Last edited by GCDEF; February 18th, 2013 at 12:06 PM.
Re: noob Dev-C++ help. Need to calc area & perimeter of a rectangle (class proj).
Originally Posted by psfign
also ive tried to use == but when i use that, it doesnt display anything
That's because you had other issues. As I said, inputting character data into a double then comparing it to other unitialized doubles couldn't possibly work. That's why I said guessing won't work and what you had wasn't even close. Look at my previous post.
Re: noob Dev-C++ help. Need to calc area & perimeter of a rectangle (class proj).
i got it now. I had changed all the individual letters to char but still had type as double. So after reading again what you said about the types again, i tried changing type as well and walla!
Is there any reason why you used multiple if statements? Was it part of the exercise specification? as it can be done using fewer statements. Also you output the type of vehicle in uppercase letters (M S etc) but only test for lowercase letters (m s etc).
You should learn how to use the debugger to find out what is actually happening when your code doesn't work as expected. Time invested in learning how to debug programs using the debugger is time well spent. It will repay itself many times over as you start to write more complicated programs.
If you are thinking about investing in a good tutorial book I would advise against any published prior to about 2001 as the c++ language changed before then to become the ANSI c++ standard.
Bookmarks