我的主函数中有一些 "expected primary-expression before 'int' " 类型的错误。怎么了?
I've got some errors of type "expected primary-expression before 'int' "in my main function. What's wrong?
#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);
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 指针问题:从不兼容的类型"int"分配给"int *"
- 数组类型 int[n][n] 不可赋值,因为表达式必须具有常量值
- 错误:数组下标的类型"int[int]"无效
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 类型为 "int*" 的参数与 C++ 中错误类型"int**"参数不兼容
- 类型"int"和"const char [15]"到二进制"运算符<<"的无效操作数^
- 从类型bankAccount的返回值到函数返回类型int没有可行的转换
- for 循环说 - 错误 成员引用基类型"int [13]"不是结构或联合
- 运行时错误:有符号整数溢出:964632435 * 10 无法在类型 'int' 中表示
- 如何增加模板类型 int 参数?
- 尝试使用 Array 类的模板构造整数数组时,错误:为什么数组类型"int [5]"不可分配,
- 如何为底层类型 int 的枚举专门化类
- 数组下标编译的无效类型'int[int]'由于 -Wfatal 错误而终止
- 不能将 "const char*" 类型的值分配给类型 "int" 的实体
- 数组下标的无效类型INT [INT]
- 请求在"伺服控制器"中请求成员"附加",该成员属于非类类型"int"
- 数组类型 'int [8]'不可分配
- 未声明的标识符和类型"int"从 main 调用类时出现意外错误