如何解决错误:预期的标识符或'(' [英] How to solve error: expected identifier or '('

查看:139
本文介绍了如何解决错误:预期的标识符或'('的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编程时遇到问题。
我一遍又一遍地收到这个错误;

I've got a problem with something I'm programming. I get this error over and over;

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.

我在互联网上进行了搜索,但找不到问题..
在<$ c $之后删除了; c> int main(void)没有帮助

I searched all over the internet but couldn't find the problem.. removing the ; after int main(void) didn't help

这是我的代码:

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

我一直在努力解决这一问题,但我

I've been trying to solve this problem for a few days, but i just can't figure it out!

非常感谢!

推荐答案

您使用do / while嵌套了循环。确保每个以do开头都以while结束。

You got nested loop with do/while. Make sure that each start with do end with while.

就像文件末尾一样, while不正确。

Look like at the end of file, the "while" is not correct.

printf("\n");
rows++;

while (rows <= height);
}

这可能是您在 while(行< ; = height);'

That could be you missing the close '}' before 'while (rows <= height);'

正确的代码可以是:

int main(void)
{

    //Ask User for Height, and check

    int a, b, rows, height;
    a = 0;                    // <- removed int
    b = 0;                    // <- removed int
    rows = 1;                 // <- removed int

    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++;
    }                             // <- add }
    while (rows <= height);
}

这篇关于如何解决错误:预期的标识符或'('的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆