Welcome fellow students, register yourself and dive into asking questions, giving answers and helping the community learn with you.

stuck on pset1

+2 votes
asked Feb 19, 2015 in Pset1 by bezerk01 (530 points)
edited Feb 19, 2015 by bezerk01
So I"m on pset 1 and I'm stuck on part 2. I already did the first part which is to ask the user for a positive number between 0 and 23 but when I get to making the boxes I'm stumped. After watching the walkthrough 100's of times Zamyla says, to get the correct number of hashes, that for every row number n, there are n + 2 hashes. I just don't know how to compare an integer with a string. Like, int i=0, i=i+2#'s, print hashes? I don't have the luxury of office hours or tutor but if you could help me out without giving me the answer that would be great!

 

Thanks

 

p.s. I don't have the book, so if the book helps a lot than it would explain why I'm having trouble .

2 Answers

+1 vote
answered Feb 19, 2015 by Faïza Harbi (11,960 points)
selected Mar 8, 2015 by bezerk01
 
Best answer

So, not exactly:

First:

You deal with spaces (replace them by * until you 're sure it works, it's easier to see the result that way) first, alone, then you deal with sharps, alone. For each row.

Pseudocode would be like:

For each row aka height value increasing do:

    For each time I have to output a space

          printf space(s)

    For each time I have to output a sharp

         printf sharp(s)

next row so not the same height.

For a height of 1 you have "*##" which is 1 space then 2 #

For height 3 (remember C is 0 indexed so the first row is row 0):

2 spaces 2 #                       **##

1 space 3 #                        *###

0 space 4 #                       ####

Now you have to find the correlation between the spaces and sharps given a height.

How height (aka row index increasing ) influences each row AND how many spaces and sharps you have?

If you count my little pyramid's character per row you see that the SUM of spaces and sharps is always the same.

 

I hope I 've been able to help you out a bit :)

 

commented Feb 19, 2015 by bezerk01 (530 points)
Thanks! I figured it out :)
commented Feb 19, 2015 by Faïza Harbi (11,960 points)
great!! :)
commented Feb 22, 2015 by carolina_clarin (100 points)
your reply really helped, specially that last comment. its been years since I've did anything similar to programming
commented Feb 22, 2015 by Faïza Harbi (11,960 points)
Thank you carolina :)
commented Mar 6, 2015 by wtrbby (100 points)
I'm stuck on exactly the same part of pset1, and still stuck after reading your tips. After spending weeks on my own trying to figure it out, I finally started asking for help on the CS50 Facebook page. But I'm still not getting past the part where I'm apparently supposed to have for loops for each printf. Totally lost. Any other suggestions?
commented Mar 6, 2015 by Faïza Harbi (11,960 points)
did you watch the pset video on mario?
And the section?
If so tell me, we'll try to figure out a way to put you on the right tracks without giving out the answer :) No worries. Starting is the hardest part. And you start at each pset :)
commented Mar 7, 2015 by wtrbby (100 points)
Yes, I've watched the pset video on mario and the section, and the shorts, everything. Just not getting it at all. Thanks for any assistance you can provide.
commented Aug 28, 2015 by Wolfgang (120 points)
same here... I know that I have to use some kind of nested for-loop construct, but I can't seem to be able to figure it out..
+1 vote
answered Feb 22, 2015 by JohnHilton (1,570 points)
If you search on the net there are some open source books on C that you can download in PDF. Format. That might help you.
commented Feb 22, 2015 by bezerk01 (530 points)
Thanks will do!
Welcome to CS50xHelpers Q&A, where you can ask questions and receive answers from other members of the community.

190 questions

248 answers

217 comments

3,603 users

2 Online
0 Member And 2 Guest
...