0

i have been trying to solve this problem :

:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) handles a height of 0 correctly
:) handles a height of 1 correctly
:( handles a height of 2 correctly
\ expected output, but not "###\n"
:( handles a height of 23 correctly
\ expected output, but not "#############\n"
:( rejects a height of 24, and then accepts a height of 2
\ expected output, but not "###\n"
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""

Code:

#include <stdio.h>
#include <cs50.h>

int main()

{
 //The first thing i did, was declaring my variables
 int n; //int n is the choosen number (that you choose)
 int h; //is the height
 int spce; //are the spaces
 int hsh; //are the #

do
{
    printf("Please choose a number from 0-23: ");//here i ask the "user" to choose the number

    n=GetInt();

    if (n==0)
    {
      return 0;  // Here is a loop that i made if the "User" chooses 0 so it asks again
    } 

} while (n<0 || n>23); 

for (h=0; h<n ; h++) //if the height is less than the number choosen (n) it adds one to the height
    {
        for (spce=0; spce < n-spce-1; spce++){}
    }
for (hsh=0; hsh<spce+2; hsh++)
    {
        printf("#");
    }
printf("\n");

return 0;
}
1

Your program is printing only one line no matter what the height is. Since there is such a significant part of the code that is missing, my recommendation is that you go back and review all of the course material and lectures for this week, particularly the concept of nested for loops, and then try again.

After a more complete attempt, if you still have questions, please ask a new question. When you do, please be more specific about your question and the details of what is wrong, what you have done, where you think the problem lies, etc.

If this answers your question, please click on the check mark to accept, to remove from the unanswered question pool. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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