这个C程序不会编译/运行?

时间:2014-08-21 11:36:53

标签: c

该程序不会在Code :: Blocks上编译。我尝试在其中更改不同的值,但无论我做什么它都不会编译。任何人都可以帮助我吗?

#include <stdio.h>
#include <windows.h>
#include <math.h>
#define PI = 3.141597
#define WAVELENGTH 70
#define PERIOD .1

int main()
{
    float i,s,x;
    i = 0;
    for (i=0;i<=PI;i+=PERIOD)
    {
        s = sin(i);
        for (x=0;x<s*WAVELENGTH;x++)
        {
            putchar('*');
        }
        putchar('\n');
    }
}

我得到的错误是:

In function 'main'
Line | 12 | error: expected expression before '=' token
=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===

3 个答案:

答案 0 :(得分:2)

从宏=中删除#define PI = 3.141597。它应该

#define PI 3.141597

答案 1 :(得分:0)

试试此代码

#include <stdio.h>
#include <windows.h>
#include <math.h>
#define PI  3.141597
#define WAVELENGTH 70
#define PERIOD .1

int main()
{
    float i,s,x;
    i = 0;
    for (i=0;i<=PI;i+=PERIOD)
    {
        s = sin(i);
        for (x=0;x<s*WAVELENGTH;x++)
        {
            putchar('*');
        }
        putchar('\n');
    }
return 0;
}

答案 2 :(得分:0)

你没有提到错误。我在您的代码中发现了两个错误

1. the "= " in #define PI = 3.141597 so remove = sign
and
2. return type in main() finction.  add return 0; in the end