在C中写一个for循环
每个人!我正在尝试解决 cs50 中的马里奥问题,当我插入这样的 for 循环时:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int height;
int i = 0;
int j = 9;
do
{
height = get_int("establish the height of the pyramide: ");
}
while (height < 1 || height > 8);
printf("you select the height of: %i\n", height);
for (i < height; i++)
{
for (j > height; j++)
{
printf("#");
}
}
}
我收到这样的错误:
mario.c:17:12: 错误:关系比较结果未使用 [-Werror,-Wunused-比较] 对于(i <= 高度;i++):
我已经尝试在循环内声明 i,但产生的错误是相同的。我在这里做错了什么?
everyone! i am trying to resolve a mario problem in cs50, and when i insert a for loop like that:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int height;
int i = 0;
int j = 9;
do
{
height = get_int("establish the height of the pyramide: ");
}
while (height < 1 || height > 8);
printf("you select the height of: %i\n", height);
for (i < height; i++)
{
for (j > height; j++)
{
printf("#");
}
}
}
i get an error like that:
mario.c:17:12: error: relational comparison result unused
[-Werror,-Wunused-comparison]
for (i <= height; i++):
i've already tried declaring i inside the loop, but the resulting error is the same. what am i doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在C中,定义了以下方式
,即它具有三个部分。第一部分是表达式(可能省略)或声明。
因此,这些循环
不满足语法。而且,第二个循环中的状况
没有意义。
还要尝试在使用它们的最小范围中定义变量。
看来您需要的是以下内容
,或者可能是以下内容
In C the for loop is defined the following way
that is it has three parts. The first part either is an expression (possibly omitted) or a declaration.
So these for loops
do not satisfy the grammar. Moreover the condition in the second loop
does not make a sense.
Also try to define variables in the minimal scope where they are used.
It seems what you need is something like the following
or maybe like the following