This is my first time using functions. Im suppose use functions ans make a area of a rectangle calc. For som reason the getArea function is not wotking, any help? I accidentaly ended up typing triangle but its suppose to rectangle.
My advice to you would be to read and focus mainly on learning to pass variables through functions properly. I think the reason it wasn't working out for you is because you weren't passing through reference
#include <iostream>
usingnamespace std;
void getWidth(int&);
void getLength(int&);
void getArea( int&, int&, int&);
int main()
{
int width = 0 ;
int length = 0 ;
int area; //You had called the Variable "area" an Int when you declared it a float at the prototype function
// It was also wrong when you tried converting two int variables into float variables.
getWidth( width);
getLength( length);
getArea(length, width, area);
// unnecessary to write int area = length * width. twice inside int main() when you declared it inside the function
system("PAUSE");
return 0;
}
void getWidth(int& width)
{
cout << "Please enter the rectangles width: "; //instead of writing the cout statement inside int main(). You can write it here.
cin >> width;
cout <<"The width is: " << width << endl;
}
void getLength(int& length)
{
cout << "Pease enter the triangles length: ";
cin >> length;
cout << "The triangles length is: " << length << endl;
}
void getArea(int& length, int& width, int& area)
{
area = length * width;
cout << "The area of the triangle is: " << area << endl;
}