Help with homework

Hello all I know you will see my question and say its a simple fix but this is all new to me and I did some research but its not sinking in. The problem is:

calculate the area of a rectangle using functions.the program will ask the user to enter the width and length of a rectangle, and then display the rectangle’s area. The program calls the following functions, which have not been written:

getLength – This function should ask the user to enter the rectangle’s length, and then return that value as a double.

getWidth - This function should ask the user to enter the rectangle’s width, and then return that value as a double.

getArea – This function should accept rectangle’s, length and width as arguments, and return the rectangle’s area. The area is calculated by multiplying the length by the width.

displayData – This function should accept the rectangle’s length, width, and area as arguments, and display them in an appropriate message on the screen.

So I came ups with this but am getting errors
// Chapter 6, Programming Challenge 2
#include <iostream>
using namespace std;

// Write the prototypes for the getLength,
// getWidth, getArea, and displayData
// functions here.
double getLength();
double getWidth();
double getArea(double length, double width);
void displayData(double length, double width, double area);

int main()
{
double length, // The rectangle's length
width, // The rectangle's width
area; // The rectangle's area

// Get the rectangle's length.
length = getLength();
{
cout << "Enter length:";
cin >> length;
return length;
}
// Get the rectangle's width.
width = getWidth();
{
cout << "Enter width:";
cin >> width;
return width;
}
// Get the rectangle's area.
double area = getArea(length, width);
{
area = length * width;
return area;
}

// Display the rectangle's data.
void displayData(double length,double width,double area);
{
cout << "The length is:" << length<< endl;
cout << "The width is:" << width << endl;
cout <<"Total area is:" << area <<endl;

return 0;
}

//***************************************************
// You must write the getLength, getWidth, getArea, *
// and displayData functions. *
//***************************************************

Thanks in Advance
Xvrl001



Use code tags [code]code goes here[/code]
Last edited on
1
2
3
4
5
6
length = getLength();
{
      cout << "Enter length:";
      cin >> length;
      return length;
}


This shouldn't be inside the main ();

Declare it outside main:
1
2
3
4
5
6
7
8
9
10
11
12
int main ()
{
     //....
     length =  getLength();
}

double getLength()
{
      cout << "Enter length:";
      cin >> length;
      return length;
}


This applies to all the functions...
@Nisheeth
Length is not declared within that function...
Oops...
int main ()
{
//....
length = getLength();
}

double getLength()
{
double length;
cout << "Enter length:";
cin >> length;
return length;
}
Topic archived. No new replies allowed.