Vaios Argiropoulos
Vaios Argiropoulos

Reputation: 387

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

Upvotes: 2

Views: 5762

Answers (3)

Jason
Jason

Reputation: 32510

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.

Upvotes: 3

Karoly Horvath
Karoly Horvath

Reputation: 96258

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

ReadinputData(h, r);

Upvotes: 1

Phil Miller
Phil Miller

Reputation: 38118

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

Upvotes: 1

Related Questions