谁能解释我程序中的循环有什么问题?

Can anyone explain me what am I doing wrong with the loops in my program?

我是 C 的新手,正在制作一个程序,其中绘制了散列网格,用户输入了网格的尺寸。我还使用 cs50 库来获取一个 int。每当我输入维度时,都不会显示任何哈希值。请帮我。提前致谢 代码:

#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");
        }
        
    }
}

在做的时候... 不要使用 return 并让 while 的条件满足。 Return指令用于从子程序或中断程序return到主程序

你可能想要这个:

  • 删除两个 return 语句,它们在这里没有任何意义。
  • 更改 while 循环(参见下面代码中的注释)。

#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");
        }        
    }
}