New To Coding/Confused about Homework Problem


#1

I have two questions relating to one problem given. I am very new to all of this and relatively stuck.

Problem:

x = 0
y = 0
DOWHILE x < 2
   DOWHILE y < 2
      y = y + 1
      Print y
   ENDDO
   x = x + 1
   Print x
ENDDO

How many numbers will be printed out after executing the above algorithm?
a 2
b 3
c 4
d 6
e 8

What is the fourth number to be printed out?
a 1
b 2
c 3
d 4
e 5

My guess for answer one would be two, but I have a feeling I am not reading into it as much as I should. Considering there is a fourth number to be printed, the answer of 2 has to be incorrect.

Anyone care to answer and explain this further? Or help me walk through this so I understand?


#2

Not sure what language this is...

Try sticking it into a console, if you're allowed. That usually helps. :stuck_out_tongue_winking_eye:


#3

My teacher wrote this herself. Many of us in the class have a hard time understand what it is she wants being that her native language is not English. Sometimes her questions are a bit confusing and use the wrong words.

The problem is related to my text book, Simple Program Design: A Step by Step Approach by Lesley Ann Robertson, and uses pseudocode. Part of our class also mainly deals with PHP related stuff as well.


#4

I've tried running it, but keep getting syntax errors. :confused:


#5

I see... This doesn't look like PHP. I'm thinking pseudocode, but I'm not sure.

I rewrote it in Python:

x = 0
y = 0
while(x < 2):
   while(y < 2):
      y = y + 1
      print y
   x = x + 1
   print x

Output:

1
2
1
2

From there, the answers should be pretty straightforward.

Hope this helps you. Enjoy. :slight_smile:


#6

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)


#7

this is absolutely pseudo code.

given @825orion has written it in python, you might want to run it here, this program will it in steps, so you can see what is happening.

What language are you guys coding in?


#8

Have it here for you. :wink:


#9

you also posted it on the forum, i am sure jbhugs12 can copy paste it into the python visualizer :slight_smile: (no offense intended)

the python visualizer allows you to run the programs into steps, to better understand it :slight_smile:


#10

Aha. Thanks for the link. I'll be sure to start doing it there, help guys out more. :smiley:


#11

I honestly don't understand much of this at all. Programming really isn't my thing, nor is coding anything. But it's required for the degree and I'm doing my best to understand. When I get back on my computer, I will run in as you guys suggested so I can understand better.

Thank you for the replies.
Jennifer


#12

what language are the assignments in? You could only find tutorials in this language, to better understand it, otherwise you might get difficulty with completing your degree


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.