-1

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!!

4
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Vilice
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.