c++ question

Thread Starter

TAKYMOUNIR

Joined Jun 23, 2008
352
//can some one please chech the wrong in this code i am new in c++ i feel that this may be easy question but it is hard for me
thanks

// 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);
double getWidth(double);
double getArea(double);
void displayData();

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(length);

// Get the rectangle's width.
width = getWidth(width );

// Get the rectangle's area.
area = getArea(length,width);

// Display the rectangle's data.
displayData(length, width, area);
system("pause");
return 0;
}

//***************************************************
// You must write the getLength, getWidth, getArea, *
// and displayData functions. *
//***************************************************
double getLength(double x)
{
cout<<"enter the length"<<endl;
cin>>x;
return x;
}
double getWidth(double x)
{
cout<<"enter the width"<<endl;
cin>>x;
return x;
}
double getArea(double x,double y)
{
double area=x*y;
return area;
}
void displayData(double x,double y,double z)
{
cout<<"the length is\t"<<x<<endl;
cout<<"the width is\t"<<y<<endl;
cout<<"the area is\t"<<z<<endl;
}
 
Last edited:

debjit625

Joined Apr 17, 2010
790
The declaration of prototype for the functions getArea() and displayData() is wrong
Always initialize your variables...
Rich (BB code):
// Chapter 6, Programming Challenge 2
#include<iostream>
usingnamespace std;
// Write the prototypes for the getLength,
// getWidth, getArea, and displayData
// functions here.
double getLength(double);
double getWidth(double);
double getArea(double,double);//Error two parameters
void displayData(double,double,double);//Error three parameters
int main()
{
//Always initialize your variables...
double length = 0, // The rectangle's length
width = 0, // The rectangle's width
area = 0; // The rectangle's area
// Get the rectangle's length.
length = getLength(length);
// Get the rectangle's width.
width = getWidth(width );
// Get the rectangle's area.
area = getArea(length,width);
// Display the rectangle's data.
displayData(length, width, area);
system("pause"); 
return 0;
}
//************************************************** *
// You must write the getLength, getWidth, getArea, *
// and displayData functions. *
//************************************************** *
double getLength(double x)
{
cout<<"enter the length"<<endl;
cin>>x;
return x;
}
double getWidth(double x)
{
cout<<"enter the width"<<endl;
cin>>x;
return x;
}
double getArea(double x,double y)
{
double area=x*y;
return area;
}
void displayData(double x,double y,double z)
{
cout<<"the length is\t"<<x<<endl;
cout<<"the width is\t"<<y<<endl;
cout<<"the area is\t"<<z<<endl;
}
Next time try to read the compiler's error...and please post your code using code tags

Good Luck
 

Thread Starter

TAKYMOUNIR

Joined Jun 23, 2008
352
thanks very much for your help and please how can i send my code

The declaration of prototype for the functions getArea() and displayData() is wrong
Always initialize your variables...
Rich (BB code):
// Chapter 6, Programming Challenge 2
#include<iostream>
usingnamespace std;
// Write the prototypes for the getLength,
// getWidth, getArea, and displayData
// functions here.
double getLength(double);
double getWidth(double);
double getArea(double,double);//Error two parameters
void displayData(double,double,double);//Error three parameters
int main()
{
//Always initialize your variables...
double length = 0, // The rectangle's length
width = 0, // The rectangle's width
area = 0; // The rectangle's area
// Get the rectangle's length.
length = getLength(length);
// Get the rectangle's width.
width = getWidth(width );
// Get the rectangle's area.
area = getArea(length,width);
// Display the rectangle's data.
displayData(length, width, area);
system("pause"); 
return 0;
}
//************************************************** *
// You must write the getLength, getWidth, getArea, *
// and displayData functions. *
//************************************************** *
double getLength(double x)
{
cout<<"enter the length"<<endl;
cin>>x;
return x;
}
double getWidth(double x)
{
cout<<"enter the width"<<endl;
cin>>x;
return x;
}
double getArea(double x,double y)
{
double area=x*y;
return area;
}
void displayData(double x,double y,double z)
{
cout<<"the length is\t"<<x<<endl;
cout<<"the width is\t"<<y<<endl;
cout<<"the area is\t"<<z<<endl;
}
Next time try to read the compiler's error...and please post your code using code tags

Good Luck
 
Top