C#,我的程序在函数运行后停止运行,我做错了什么
C#, my program stops running after the function runs, what am i doing wrong?
这是针对 cs50 马里奥金字塔问题集的。我让它在没有功能的情况下工作,但我想尝试一些不同的东西。由于用户输入符合参数的数字后发生了变化,因此程序停止。它不会像以前那样打印"#"或" "。
我正在在线学习这门课程,任何帮助将不胜感激。
#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;
}
问题出在您的函数中,请替换最后一行:
int towerheight(void)
{
int num;
do
{
printf("Your number must be between 1 - 23: ");
num = GetInt();
}
while (num <= 0 || num >= 24);
return num; // replace by this
}
您总是返回0
并且for
循环不满足条件height
因为始终0
。
相关文章:
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- 首要问题的答案让值班员搞错了
- 看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 我的C++线程做错了什么?
- 如何正确使用 >=?(a+f()+c)>=0 错了吗?
- 谁能告诉我我用 getline 做错了什么 (cpp) 格式
- 没有输出的合并排序我做错了什么?
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 在C++中使用 AKS 素数测试计算双胞胎素数 我做错了什么?
- 指针相关的UE4崩溃.我的指针哪里错了?
- 我一直试图弄清楚我在这个链表程序中做错了什么
- 我正在尝试学习如何在 c++ 中传递指针,但出现错误:没有用于调用"test"的匹配函数。我做错了什么?
- FFMPEG,C++,内存泄漏,我做错了什么?
- 我做错了什么?反向字符串 C++
- 每当我运行此程序C 时,我都会出现错误.我做错了什么
- 代码块运行错误: "Process terminated with status -1073741510" 。我做错了什么?
- c++地图值不改变运行时,我做错了什么
- C#,我的程序在函数运行后停止运行,我做错了什么