#include <iostream>
using namespace std;
//Fuction Prototype
double getLength();
double getWidth();
double getArea(double length, double width);
void displayData(double length, double width, double area);
int main()
{
double length,width,area;
//get the rectangle 's length
length=getLength();
// Get the rectangle's width.
width = getWidth();
// Get the rectangle's area.
area = getArea(length,width);
// Display the rectangle's data.
displayData(length, width, area);
system("pause");
return 0;
}
//declare getLenght fuction
double getLength()
{
double length;
cout<<'\n';
cout<<'\t'<<'\t'<<"Please enter the lenght of the rectangle:"<<endl;
cin>>length;
while(length<=0)
{
cout<<'\t'<<"***********************************************************"<<endl;
cout<<'\t'<<"*"<<'\t'<<'\t'<<'\t'<<"Bad Data Input!!!"<<'\t'<<'\t'<<" "<<"*"<<'\n';
cout<<'\t'<<"*"<<'\t'<<"Length can't be a character or a negative number"<<" "<<"*"<<'\n';
cout<<'\t'<<"*"<<'\t'<<"and must be diferent from 0 "<<'\t'<<'\t'<<'\t'<<" "<<"*"<<endl;
cout<<'\t'<<"***********************************************************"<<endl;
cout<<'\n';
cout<<'\t'<<'\t'<<"Please enter the lenght of the rectangle:"<<endl;
cin>>length;
}
return length;
}
//declare getWidth fuction
double getWidth()
{
double width;
cout<<'\t'<<'\t'<<"Please enter the width of the rectangle:"<<endl;
cin>>width;
while(width<=0)
{
cout<<'\t'<<"***********************************************************"<<endl;
cout<<'\t'<<"*"<<'\t'<<'\t'<<'\t'<<"Bad Data Input!!!"<<'\t'<<'\t'<<" "<<"*"<<'\n';
cout<<'\t'<<"*"<<'\t'<<"Width can't be a character or a negative number"<<" "<<"*"<<'\n';
cout<<'\t'<<"*"<<'\t'<<"and must be diferent from 0 "<<'\t'<<'\t'<<'\t'<<" "<<"*"<<endl;
cout<<'\t'<<"***********************************************************"<<endl;
cout<<'\n';
cout<<'\t'<<'\t'<<"Please enter the width of the rectangle:"<<endl;
cin>>width;
}
return width ;
}
//declare getArea function
double getArea( double length, double width)
{
double area = length * width;
return area;
}
//declare displayData function
void displayData(double length, double width, double area)
{
cout << "The rectangle's length is: "<< length << endl;
cout << "The rectangle's width is: " << width << endl;
cout << "The rectangle's area is: " << area << endl;
}
No comments:
Post a Comment