我刚刚开始学习 c++,并正在尝试编写一个程序来查找圆的面积。我已经编写了程序,每当我尝试编译它时,我都会收到 2 条错误消息。第一个是:
areaofcircle.cpp:9:14: error: expected unqualified-id before numeric constant
第二个是:
areaofcircle.cpp:18:5: error: 'area' was not declared in this scope
我应该怎么办?我会发一张图片,但我是新用户,所以我不能。
#include <iostream>
using namespace std;
#define pi 3.1415926535897932384626433832795
int main()
{
// Create three float variable values: r, pi, area
float r, pi, area;
cout << "This program computes the area of a circle." << endl;
// Prompt user to enter the radius of the circle, read input value into variable r
cout << "Enter the radius of the circle " << endl;
cin >> r;
// Square r and then multiply by pi area = r * r * pi;
cout << "The area is " << area << "." << endl;
}