这是用于cs50马里奥金字塔问题集。我让它在没有功能的情况下工作,但我想尝试一些不同的东西。由于用户输入数字后的更改符合参数,程序将停止。它不会打印“#”,或者像过去那样的“”。C#,函数运行后我的程序停止运行,我做错了什么?
我在网上学习这门课程,任何帮助将不胜感激。
#include <stdio.h>
#include <cs50.h>
int towerheight(void);
int main(void)
{
printf("how high would you like the tower? ");
int height = towerheight();
int pound;
int space;
for (int i = 0; i < height; i++)
{
for (space = height - i; space >= 0; space--)
{
printf(" ");
}
for (pound = 0; pound < i + 2; pound++)
{
printf("#");
}
printf("\n");
}
}
int towerheight(void)
{
int num;
do
{
printf("Your number must be between 1 - 23: ");
num = GetInt();
}
while (num <= 0 || num >= 24);
return 0;
}
这不是C#。 – crashmstr
函数返回应该是'return num'而不是'return 0' –
学习如何调试,而不是在SO上发布最小的问题。如果你在调试器中检查代码,你会发现'height'为零,所以你的'for'循环甚至不会运行,因为它没有使用'i
Quantic