2

I am new to C and was making a program where a hash grid is drawn and the user inputs the dimensions of a grid. I also used the cs50 Library to get a int. When ever I input the dimensions, no hashes show up. Please help me. Thanks in advance Code:

#include <stdio.h>
#include <cs50.h>
int main(void){
    int x;
    int y;
    do{
        x=get_int("Width of the hash floor: ");
        y=get_int("Length of the hash floor: ");
        return x;
        return y;
    } while (x>1);
    for (int n=0;n<x;n++){
        printf("#");
        for(int a=0;a<y;a++){
            printf("#\n");
        }
        
    }
}
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
AouxWoux
  • 71
  • 5

2 Answers2

1

You probably want this:

  • remove both return statements, they don't make any sense here.
  • change the while loop (see comment in the code below).

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

int main(void) {
    int x;
    int y;

    do{
        x = get_int("Width of the hash floor: ");
        y = get_int("Length of the hash floor: ");
    } while (x < 1 || y < 1);  // ask for width and length until both
                               // x and y are larger than 0

    for (int n = 0; n < x; n++) {
        printf("#");
        for (int a = 0; a < y; a++) {
            printf("#\n");
        }        
    }
}
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
-1

in the do while ... Don't use return and let the condition of while fulfill. The Return instruction is used to return to the Main Program from a Subroutine Program or Interrupt Program

Gabriel
  • 89
  • 1
  • 5