A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
problem set 1:
polpak suggested i write a program that prints integers from 1 to 100. i wrote one that computes up to the value 100 through an iterative loop but i don't know how to actually print each integer from 1 through 100. here's a link to the program.
http://dpaste.com/490649/
how do i print the list of integers?
anonymous
 5 years ago
problem set 1: polpak suggested i write a program that prints integers from 1 to 100. i wrote one that computes up to the value 100 through an iterative loop but i don't know how to actually print each integer from 1 through 100. here's a link to the program. http://dpaste.com/490649/ how do i print the list of integers?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0replying to my own post here! i just saw that polpak suggested i simply count to 100. which this program accomplished. . .

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0True. Ok, so now make it print each in turn.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0i don't know how to do that. eek! i hate asking for you to do this for me but i am unfamiliar with how to print each value.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0that's ok. Let me ask you this, what would happen if you removed line 5 from the program?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0not sure. . .i'll go remove it and see what happens.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0also, while you're doing that. Print out the value of itersLeft before and after the loop

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0when i remove y=y+x, the print value returned is simply 1. if I print itersLeft before the loop, I get 99. if i print it after, i get 0.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Ok, so itersLeft is 99 before you execute the loop so we can actually remove the y and the x variables entirely and just say itersLeft = 99. That might make things more clear. Now what happens when you print itersLeft inside the loop?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0hmmm. i put the statement 'print itersLeft' in the iterative statement and nothing happened.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0dpaste your current version of the code and I'll try to figure out what the problem is. It should certainly have done something.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0i just redid it. something had gone wrong the first time with my spacing. this time i got a list with values from 98 down to 0. i'm going to increase my itersLeft to 102x and see what comes back.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0wait. You should have removed x and y. You only need to have itersLeft. The x and y variables were specific to the problem trying to be solved in the lecture. For standard iteration you only need 1 counter variable (or some other boolean condition) Just set itersLeft = 99 and see what happens without the x and y

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0am i just removing y=y+x or am i completely removing y from the program?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0you don't need x or y at all. Where you initialize the itersLeft variable, you can just set it directly to 99 (the result of 100x when x is 1)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0alright. now i've gotten a list from 99 to 0. here's the program: http://dpaste.com/490719/

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0You don't need the x. It's not doing anything useful. See http://dpaste.com/490708/

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ah! makes sense. being so new to this, i still don't understand a lot of what i'm doing. so, i'm parroting what i see in lecture until the comprehension sets in!

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0no problem. I just wanted to simplify the example so you have an easier time understanding how it works. Now, you said that you had a list of numbers from 99 to 0. Techically your version goes from 98 to 0, while mine goes from 99 to 1. See if you can modify my version so that it only goes from 9 to 1.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Also I wanted to clarify something you said. This code does not 'give' a list of numbers. To be correct we can simply say that it will loop 99 times. Each time it loops it will print one number (the current number stored in itersLeft) then change the current number to be the next number.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Or even more correctly. It will loop until itersLeft is NOT greater than 0. And each time it executes the body of the loop we move itersLeft closer to that end case. (itersLeft is less than or equal to 0)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0i modified the program so it prints from 9 down to 1. i see how the print statement needs to come before the operation on itersLeft in order to start the list at the current value of itersLeft. i don't have a ton of time to continue working on this so i will need to take a break for now. my next step then will be to have the program only print odd numbers?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0yes exactly. Have it print the odd ones.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok. i'll work on that later today or tomorrow and then come back for help if i need it. are you on the open study forum often?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0as a hint, think about how far the next odd number is from the current odd number

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0this forum? or the main openstudy one?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0this forum, i suppose.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I'm here often. I don't use the regular openstudy thing as much.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok, great! that's really nice of you to hang out in an intro forum in order to help us newbies.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I also tutor elsewhere, and I'm hoping to someday teach, so this is good practice =)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0well you're off to a good start helping me so i really appreciate it! and, i hope that if you get a job teaching basic CS, it pays well so you aren't scratching your eye balls out over all the dumb questions for nothing.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0It's actually pretty rewarding by itself. I've done things that pay well, and they weren't nearly as much fun.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.