简体   繁体   中英

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);

}

The errors are the following:

-------------- Build: Debug in eeee ---------------

Compiling: main.cpp /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp: In function 'int main()': /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:15: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:22: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:19: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:25: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:31: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:38: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:16: error: expected primary-expression before 'int' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:22: error: expected primary-expression before 'int' Process terminated with status 1 (0 minutes, 0 seconds) 8 errors, 0 warnings

You don't have to re-declare the data-types of an argument when calling a function. So change:

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

To simply:

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

As it stands right now with your current un-corrected code, you're basically re-declaring the function without a valid return type inside of main rather than calling the function with the appropriate arguments. That's going to throw a compiler error.

You don't need to specify the types of a function's arguments when calling it.

In other words, line 39 should read

Readinputdata(h, r);

When you calling a function don't specify argument types.

ReadinputData(h, r);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM