【发布时间】:2012-12-23 14:12:10
【问题描述】:
我正在编程的东西有问题。 我一遍又一遍地收到这个错误;
jharvard@appliance (~/Dropbox/pset1): make mario
clang -ggdb3 -O0 -std=c99 -Wall -Werror mario.c -lcs50 -lm -o mario
mario.c:23:5: error: expected identifier or '('
do
^
mario.c:32:1: error: expected identifier or '('
do
^
2 errors generated.
我搜索了整个互联网,但找不到问题..
删除 ;在int main(void) 没有帮助之后
这是我的代码:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void);
//Ask User for Height, and check
int a, b, rows, height;
int a = 0;
int b = 0;
int rows = 1;
do
{
printf ("Height: ");
height = GetInt();
}
while (height <=0 || height > 23);
//build half pyramid
do
{
do
{
printf("r");
a++;
}
while (a < height - rows);
do
{
printf("#");
b++;
}
while (b < rows + 1);
printf("\n");
rows++;
while (rows <= height);
}
我这几天一直在尝试解决这个问题,但我就是想不通!
非常感谢您!
【问题讨论】:
-
修复你的缩进,最后一个人看起来真的很奇怪。
-
是因为在
while的printf之前缺少}(取决于真实的身体周期,因为压痕不好不知道你真正的意思) -
+1 @Mat 所说的。最后一段时间看起来应该在右括号之后(属于第二个
do)。但是缩进你的代码,这样的错误对你来说是显而易见的。如果你不缩进你的代码,那么你应该遭受这样的痛苦。