A friend has just started an IT course. Her homework the other day was to write a flow chart to display all the odd numbers from 1 to 99. I am no expert but I could see some problems she got wrong in her firs attempt so I assisted her. The teacher marked it as incorrect.
I had X = 1 (then) display (then) if x< 100 a sub routine X = X + 2 (then) return to main routine before display. The teacher said the display had to be in the main routine after the exit for the sub routine. I say this would only display 99.
If this is too hard to follow I will attach the flow chart next time, please explain!!

as for as i know the flow chart would be like this

start
|
i=1
|
|-----------------------------------------------|
if i<100__yes__ print i-------i=i+2-----print i
|no
|
end

Your both wrong (your teacher and you).

Your flow chart will display 101 as the last number. Start, X=99, display 99, Test OK, add 2 so x=101, loop, Display 101, test EXIT.

Your teachers comment that to change the display to the exit and you will get the same result, only it will only display one time as you say. So you would see 101 not 99.

You need to display X after you test the value and before you add to X. So you test, then display, then add, then loop.

I agree with TPHTA

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.