Skip to main content
added 239 characters in body
Source Link

I can't figure out the problem in my code, it successfully creates a pyramid but doesn't reprompt when value other than 1-8 is entered, also it gives a space before printing the pyramid, causing errors in check50. Please correct this code. The output I get with Check 50 is like:

handles a height of 2 correctly
expected "" #  #"\n"##  ...", not ""  #  #"\n" ##..."
are you printing an additional character at the beginning of each line?

and here is the code:

   #include<stdio.h>
#include<cs50.h>
int main(void)
{
    int n;
    input:
 n = get_int("Enter a number=\n");
 if(n>=1&&n<=8)
 {
  for(int i=1;i<=n;i++)                             //FOR THE RIGHT LEANING TRIANGLE
  {
     for(int k=n-i;k>=0;k--)
     {
       printf(" ");
     }
     for(int j=1;j<=i;j++)
     {
         printf("#");
     }
     printf("  ");                                       //FOR THE 2 SPACES
     for(int b=1;b<=i;b++)                              //FOR THE LEFT LEANING TRIANGLE
        {
            printf("#");
        }
        printf("\n");
   }

 }
 else
{
    goto input;
}
 }

I can't figure out the problem in my code, it successfully creates a pyramid but doesn't reprompt when value other than 1-8 is entered, also it gives a space before printing the pyramid, causing errors in check50. Please correct this code.

   #include<stdio.h>
#include<cs50.h>
int main(void)
{
    int n;
    input:
 n = get_int("Enter a number=\n");
 if(n>=1&&n<=8)
 {
  for(int i=1;i<=n;i++)                             //FOR THE RIGHT LEANING TRIANGLE
  {
     for(int k=n-i;k>=0;k--)
     {
       printf(" ");
     }
     for(int j=1;j<=i;j++)
     {
         printf("#");
     }
     printf("  ");                                       //FOR THE 2 SPACES
     for(int b=1;b<=i;b++)                              //FOR THE LEFT LEANING TRIANGLE
        {
            printf("#");
        }
        printf("\n");
   }

 }
 else
{
    goto input;
}
 }

I can't figure out the problem in my code, it successfully creates a pyramid but doesn't reprompt when value other than 1-8 is entered, also it gives a space before printing the pyramid, causing errors in check50. Please correct this code. The output I get with Check 50 is like:

handles a height of 2 correctly
expected "" #  #"\n"##  ...", not ""  #  #"\n" ##..."
are you printing an additional character at the beginning of each line?

and here is the code:

   #include<stdio.h>
#include<cs50.h>
int main(void)
{
    int n;
    input:
 n = get_int("Enter a number=\n");
 if(n>=1&&n<=8)
 {
  for(int i=1;i<=n;i++)                             //FOR THE RIGHT LEANING TRIANGLE
  {
     for(int k=n-i;k>=0;k--)
     {
       printf(" ");
     }
     for(int j=1;j<=i;j++)
     {
         printf("#");
     }
     printf("  ");                                       //FOR THE 2 SPACES
     for(int b=1;b<=i;b++)                              //FOR THE LEFT LEANING TRIANGLE
        {
            printf("#");
        }
        printf("\n");
   }

 }
 else
{
    goto input;
}
 }
Source Link

Query related to Mario program(more) in CS50 pset1

I can't figure out the problem in my code, it successfully creates a pyramid but doesn't reprompt when value other than 1-8 is entered, also it gives a space before printing the pyramid, causing errors in check50. Please correct this code.

   #include<stdio.h>
#include<cs50.h>
int main(void)
{
    int n;
    input:
 n = get_int("Enter a number=\n");
 if(n>=1&&n<=8)
 {
  for(int i=1;i<=n;i++)                             //FOR THE RIGHT LEANING TRIANGLE
  {
     for(int k=n-i;k>=0;k--)
     {
       printf(" ");
     }
     for(int j=1;j<=i;j++)
     {
         printf("#");
     }
     printf("  ");                                       //FOR THE 2 SPACES
     for(int b=1;b<=i;b++)                              //FOR THE LEFT LEANING TRIANGLE
        {
            printf("#");
        }
        printf("\n");
   }

 }
 else
{
    goto input;
}
 }