0

I have a program which it is supposed to print Mario-like towers on each side corresponding to the amount you input. Everything seems to work but when I try to check the code it gives the error ":( rejects a height of 9, and then accepts a height of 2 expected program to reject input, but it did not" I tried putting a height of 9 and height of 2, they both should work but I still am receiving the error

#include <stdio.h>
int main(void)
{
    int num = 1;
    int num1 = 1;
    int towers;
    do{
        towers = get_int("Height ");
    }
    while(towers < 1);
    int figure = towers;
    for(int i = 1; i <= towers; i++) { // repeats for length, should work
    for(int e = 0; e < figure-1; e++) { // prints .. before the # amount of length-1
        printf(" ");
    }
    figure--;
        for(int x = 0; x < num; x++) { // prints the #
            printf("#");
        }
        num++;
        printf("  ");
        for(int y = 0; y < num1; y++) { // prints the #
            printf("#");
        }
        num1++;
        printf("\n");

    }
    return 0;
    }
3
  • Please use style50 on your code. It is very hard to read. Commented Dec 23, 2022 at 21:38
  • Also i would like it if you could provide the error. Commented Dec 23, 2022 at 21:39
  • And, you need to #include <cs50.h> Commented Dec 23, 2022 at 21:40

1 Answer 1

1

You are close, but there are a few errors. I copied and ran your code, and it wasn't outputting the pyramids as they were meant to. I would encourage you to test out your code in the terminal on your own before using check50. First, get_int is a function from the CS50 library, so you'll have to include that in your preprocessor directives (#include <cs50.h> at the top) so it can compile correctly. Secondly, get_int is currently only checking if the height that the user inputted is below 1 (while towers < 1), so you will have to change that so it does not allow users to input a number outside the range of 1-8. Finally, your for loops are not outputting the pyramids correctly because of the conditions you have set. I hope this helps a bit. I am also taking CS50, and it's challenging me as well! Best of luck. Keep grinding!

You must log in to answer this question.

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