Rectangle Area Homework
Mar 22, 2016 at 11:24pm UTC
For my homework assignment, I'm supposed to create a program that asks for length and width of a rectangle, calculate the area then display it using 4 different functions which are shown in my code. I have no errors when I compile and when I run it, it seems to work until I get to the final part. The area keeps displaying as some long decimal number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <iostream>
using namespace std;
double getLength();
double getWidth();
double getArea(double length, double width);
void displayData(double length, double width, double area);
int main()
{
double length,width,area;
length=getLength();
width=getWidth();
getArea(length,width);
displayData(length,width,area);
}
double getLength()
{
double length;
cout<<"Enter the length of the rectangle: " ;
cin>>length;
return length;
}
double getWidth()
{
double width;
cout<<"Enter the width of the rectangle: " ;
cin>>width;
return width;
}
double getArea(double length,double width)
{
double area;
area=length*width;
return area;
}
void displayData(double length, double width, double area)
{
cout<<"The length is: " <<length<<endl;
cout<<"The width is: " <<width<<endl;
cout<<"The area is: " <<area<<endl;
}
Mar 22, 2016 at 11:56pm UTC
What does line 15 do?
Mar 23, 2016 at 6:53am UTC
Yes, see line 15 and what is that missing for line 16. Read the run-time error carefully. :)
Topic archived. No new replies allowed.