我的主函数中有一些 "expected primary-expression before 'int' " 类型的错误。怎么了?

I've got some errors of type "expected primary-expression before 'int' "in my main function. What's wrong?

本文关键字:类型 int 怎么了 错误 before 函数 primary-expression expected 我的      更新时间:2023-10-16
#include <iostream>
using namespace std;
const double PI = 3.14;
void ReadinputData(int& a, int& b){
cout << " Give me the height of the Cylinder: ";
cin >> a ;
cout << " Give me the radious of its base: ";
cin >> b ;
}

void ComputetheResults(int a,int b,int &x,int &y){
x= 2*PI*b*a;
y= PI*a*b*b;
}
void DisplayAnswers(int a, int b){
cout<< "the surface are of the cylinder is: "<< a<< endl;
cout<< "the volume of the cylinder is: "<< b << endl;
}

int main()
{
int h,r,A,V;
h=0;
r=0;
A=0;
V=0;
ReadinputData(int h, int r);
ComputetheResults(int h,int r,int &A,int &V);
DisplayAnswers(int A,int V);
}

错误如下:

-------------- 构建:在eeee调试 ---------------

编译:main.cpp/home/vaios/desktop/ertt/eeeeee/eeeeee/main.cpp:在函数' int main() '中:/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:15:错误:预期的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:22:错误:预期的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:19:错误:期望的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:25:错误:期望的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:31:错误:期望的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:38:错误:期望的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:16:错误:预期的主表达式在' int '之前/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:22:错误:预期的主表达式在' int '之前进程以状态1终止(0分0秒)8个错误,0个警告

在调用函数时不必重新声明参数的数据类型。所以改变:

ReadinputData(int h, int r);
ComputetheResults(int h,int r,int &A,int &V);
DisplayAnswers(int A,int V);

:

ReadinputData(h, r);
ComputetheResults(h, r, A, V);
DisplayAnswers(A, V);

在当前未更正的代码中,您基本上是在没有有效返回类型的情况下在main中重新声明函数,而不是使用适当的参数调用函数。这会抛出编译器错误

调用函数时不需要指定参数的类型。

换句话说,第39行应该是

Readinputdata(h, r);

调用函数时不要指定参数类型

ReadinputData(h, r);