Hi. My name's Brianne and I just now started this semester taking Programming, Logic and Design. I have a homework problem, and what blows is this class is online, so I have to read the book, and write 100 times to get something down ... and I just don't get it.

Basically, I have to debug this code and I don't even know what kind of language it's in. The specific instructions were:

"This pseudocode segment is intended to describe computing the number of miles per gallon you get with your automobile. The pgoram segment should continue as long as the user enters a positive value for miles traveled.":

input gallonsOfGasUsed
input milesTraveled
while milesTraveled > 0
    milesPerGallon = gallonsOfGasUsed / milesTraveled
     print milesPerGal
endwhile

I'm thinking that I have to put "do" before the input and then indent the input, but I'm not totally sure. So, this is what I got:

input gallonsOfGasUsed
[B]do[/B]
input milesTraveled
while milesTraveled > 0
    milesPerGallon = gallonsOfGasUsed / milesTraveled
     print milesPerGal
endwhile

I'm looking at the code examples in the book and they look like:

do
     pay bills
while more bills remain to be paid

or...

pay bills
while there are more bills to pay
     pay bills
endwhile

So, I'm thinking now maybe it's supposed to be modeled after the second one because of the endwhile:

input gallonsOfGasUsed
input milesTraveled
do
    milesPerGallon = gallonsOfGasUsed / milesTraveled
while milesTraveled > 0
     print milesPerGal
endwhile

I'm not sure, though. Everyone who has taken this class before me told me they never had to debug anything. I think teachers are assuming that we all can code fairly well before we come into Programming, Logic and Design and that's just not it.

-_- Thanks for looking!

>>I don't even know what kind of language it's in
It is pseudocode, which means it is not written in any computer language. Its purpose is to show the logic regardless of programming language.

What you will want to do is copy the input line (do NOT just move it) to the end of the loop immediately after the print line.

Oh, okay. So it's not any specific language, it's just an example?

Logical my derriere. It's just really weird to be plopped into learning this stuff when we just began the semester and haven't been taught anything, but I thank you.

I don't need the do? I just put the inputGallonsofGas after the print and before the endwhile?

I hate feeling dumb. And I'm trying to learn this stuff, it's just a lot to take in all at once.

>>I hate feeling dumb.
we all felt like that at first. So don't worry about it and just keep studying. You'll get the hang of it.

>>I don't need the do?
No -- it is a language-specific key word and loop type.

There are lots of other ways to solve the problem, but if you have to just change the pseudocode they gave you then asking the same question twice is the best way. Ask the question before the loop starts then again just before the loop ends.

Oh, okay. So it's not any specific language, it's just an example?

In a sense. It's a list of instructions to accomplish the job. Another example of pseudocode would be:
1) Open the car door
2) Slide in behind the steering wheel
3) Close the door
4) Insert the key in the ignition
etc

When you actually get to the car, you then have to figure out whether you pull up on a handle, or push a button to unlach the door before opening it. And so on. Pseudocode is generic instructions to get the job done. You then translate those instuctions into the specific language you are programming in.

This article has been dead for over six months. Start a new discussion instead.