I want to be able to change my code so that each function will return the respected calculation (i.e. rect_area will return the area). How would I go about doing so?
All help is appreciated!
Thank you,
Huppa
*I also wanted to add if there is anything wrong with my current code, please tell me, I am new to functions as a whole and they are not my strong suit at the moment.
#include <iostream.h>
void rect_area(float, float);
void rect_peri(float, float);
void rect_vol(float, float, float);
void main (void)
{
float length, width, height;
cout<<"What is the length of the rectangle?\n";
cin>>length;
cout<<"What is the width of the rectangle?\n";
cin>>width;
cout<<"What is the height of the rectangle?\n";
cin>>height;
rect_area(length, width);
rect_peri(length, width);
rect_vol(length, width, height);
}
void rect_area(float L, float W)
{
float area;
area=(L*W);
cout<<"The area of the rectangle is: "<<area<<endl;
}
void rect_peri(float L, float W)
{
float peri;
peri=((2*L)+(2*W));
cout<<"The perimeter of the rectangle is: "<<peri<<endl;
}
void rect_vol (float L, float W, float H)
{
float vol;
vol=(L*W*H);
cout<<"The volume of the rectangle is: "<<vol<<endl;
}
What compiler are you using? The current standard doesn't require C++ Standard Library headers to have the .h ending, main must return int, and the C++ Standard Library is in the std namespace so you either have to have std:: in front or do like I did below (which is considered bad by some) and do using namespace std; under the includes