#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);
}
错误如下:
-------------- Build:在eeee中调试---------------
编译:main.cpp /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:在函数'int main()'中: /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:15:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:22:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:19:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:25:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:31:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:38:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:16:错误:在'int'之前预期的primary-expression /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:22:错误:'int'之前的预期primary-expression 进程终止,状态为1(0分0秒) 8个错误,0个警告
答案 0 :(得分:3)
调用函数时,不必重新声明参数的数据类型。所以改变:
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
内没有有效返回类型的情况下重新声明函数,而不是用适当的参数调用函数。这会引发编译器错误。
答案 1 :(得分:1)
调用函数时,不需要指定函数参数的类型。
换句话说,第39行应为
Readinputdata(h, r);
答案 2 :(得分:1)
调用函数时,不要指定参数类型。
ReadinputData(h, r);