0

I created a loop to print the required spaces and a loop to print the required hashes. The program works. However, checkcs50 doesn't like it. Here are checkcs50 statements:

:( handles a height of 0 correctly
\ expected an exit code of 0, not output of "Please enter a whole number 
from 1 to 2..."

:( handles a height of 1 correctly
\ expected output, but not "\n##\n"

:( handles a height of 2 correctly
\ expected output, but not "\n ##\n###\n"

:( handles a height of 23 correctly
\ expected output, but not "\n                      ##\n           ..."

:( rejects a height of 24
\ expected output, but not "\n                      ##\n           ..."

Here are my questions:

  1. Are we to reject 0 as an input? Currently I do because it doesn't make sense to build a zero level pyramid.

  2. It appears checkcs50 doesn't like my printf statements to print the spaces and hashes. I'm confused. I met the criteria for the assignment by printing a pyramid. How am I to print hashes and spaces without printf statements? As I said, I created a loop for each. What kind of statement am I to use to print hashes and spaces if not a printf statement?

Please help Thanks.

2 Answers 2

0

First, run the staff version for these various tests. Watch exactly what it displays. For example, run a height of 0. Does it reject it? It doesn't, because 0 is a non-negative integer, which is acceptable per the spec.

:( handles a height of 1 correctly
\ expected output, but not "\n##\n"

When you run the staff version with a height of 1, you will see this

jharvard@appliance (~/Dropbox/pset1): ~cs50/pset1/mario
Height: 1
##
jharvard@appliance (~/Dropbox/pset1):

When you run your version, I expect you see this:

jharvard@appliance (~/Dropbox/pset1): ./mario
Height: 1

##
jharvard@appliance (~/Dropbox/pset1):

Do you see the difference?

Of course, you must use printf, but be sure not to print anything extra that is unexpected.

2
  • Found the problem. Thanks for your help!
    – Chess Dad
    Jul 21, 2014 at 0:55
  • You're welcome. My philosophy is to help folks to figure out the correct answer for themselves rather than just giving it straight out so I'm glad that you found my reply helpful.
    – curiouskiwi
    Jul 21, 2014 at 1:15
0

Are we to reject 0 as an input?

No, but when your program receives 0 as the height, it shouldn't output anything and it should exit immediately.

How am I to print hashes and spaces without printf statements? What kind of statement am I to use to print hashes and spaces if not a printf statement?

Nothing is wrong with using printf(). Your program just shouldn't output a newline character (i.e., '\n') before printing the half a pyramid and that's probably what makes check50 reject the results of your program.

Lastly, your program should reject heights < 0 and > 23. Meanwhile, your program isn't supposed to print anything as the height is 24 (or higher).

3
  • Thanks for responding. Not sure what you mean by "you shouldn't just output a newline character (i.e., '\n') before printing the half a pyramid". How else are we to move down to the next line to print the next line of hashes? I guess I'm missing something here.
    – Chess Dad
    Jul 21, 2014 at 0:51
  • @ChessDad I just meant not to print a newline before starting to print the first row of your half a pyramid (if the height is > 0). Of course you should move to the next line by printing a newline character, but you shouldn't print a newline character initially (i.e., before building your pyramid).
    – kzidane
    Jul 21, 2014 at 1:03
  • Thanks Kareem. I figured that out and deleted the line break. I appreciate your help.
    – Chess Dad
    Jul 21, 2014 at 1:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .