0
#include <iostream> #include<iomanip> using namespace std; //prototypes void getData(double base,double height); void getData(double radiusa,double radiusb); void printData(double rec_area,double elli_area); void getData(double rpar1,double rpar2); void printData(double vpar1,double vpar2); //Declare variables double base,height, radiusa, radiusb, rec_area, elli_area,rpar1, rpar2, vpar1,vpar2; //Declare a global constant named PI equal to 3.141592; const double PI = 3.141592; int main() { //Print on the screen “For the rectangle” cout << "For the rectangle" << endl; //Call void function for base and height getData(base, height); //Print on the screen “For the ellipse” cout << "For the ellipse" << endl; //Call void function for lengths getData(radiusa, radiusb); //Calculate the area and store the result for rectangle rec_area = base * height; //Calculate the area and store the result for ellipse elli_area = PI * radiusa * radiusb; //Call void function that receives the two areas and returns them printData(rec_area, elli_area); //Get both values from the keyboard and store them in rpar1 and rpar2. getData(rpar1, rpar2); //Format to use fixed point printData(vpar1, vpar2); return 0; } //call functions void getData(base, height) { return; } void getData(radiusa, radiusb) { return; } void printData(rec_area, elli_area) { cout << "The area of the rectangle is " << rec_area << endl << endl; cout << "The area of the ellipse is " << elli_area << endl << endl; return; } void getData(rpar1, rpar2) { return; } void printData(vpar1, vpar2) { cout << "Please enter two lenghts: " << endl << endl; cout << fixed << showpoint << setprecision (1); return; } 

I have been messing with the code here and there so if it looks ugly I'm sorry. Also I'm a noob. Here are the errors:

error C2448: 'getData' : function-style initializer appears to be a function definition error C2448: 'getData' : function-style initializer appears to be a function definition error C2448: 'printData' : function-style initializer appears to be a function definition error C2448: 'getData' : function-style initializer appears to be a function definition error C2448: 'printData' : function-style initializer appears to be a function definition 
1
  • 1
    Take some time to learn the basics of C++ first. Eg. about functions → cplusplus.com/doc/tutorial/functions . Also read the next page where overloading is discussed. Commented Nov 5, 2015 at 2:50

1 Answer 1

2

First of all, writing a function declaration above main is a good technique to write functions.

The errors you see in your code are because when you write the actual body of the functions, you need to specify the type of the parameters again. Your code for the functions should be

//declare functions void getData(double base, double height); void getData2(double radiusa, double radiusb); void printData(double rec_area, double elli_area); void getData3(double rpar1, double rpar2); void printData2(double vpar1, double vpar2); int main(void) { //your code here } //write body of functions void getData(double base, double height) { return; } void getData2(double radiusa, double radiusb) { return; } void printData(double rec_area, double elli_area) { cout << "The area of the rectangle is " << rec_area << endl << endl; cout << "The area of the ellipse is " << elli_area << endl << endl; return; } void getData3(double rpar1, double rpar2) { return; } void printData2(double vpar1, double vpar2) { cout << "Please enter two lenghts: " << endl << endl; cout << fixed << showpoint << setprecision (1); return; } 

EDIT: Oh, and roeland is right, when you overload functions they need to have something different in their parameters, otherwise they will seem identical to the compiler.

Sign up to request clarification or add additional context in comments.

2 Comments

I already moved them up, but now i get new errors, such as:error C2084: function 'void getData(double,double)' already has a body @Savvas
Let's take it from the beginning. Above main, you need to declare your functions as you did. After main, you have to write the code of these functions. When you write the code, you need to write the whole body and head, so you need to write the type of the parameters. Another problem in your code was that you overloaded functions in a wrong way. When you use overloading, two functions with the same name need to have some significant difference in their declaration. One such difference is having different types as parameters. (changing only the name of theparameters is pointless)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.