13,055,629 members (53,421 online)
Rate this:
See more:
make a function that will compute the area of a rectangle, square ang circle. help me pls.
Posted 9-Mar-11 23:34pm
Updated 10-Mar-11 14:11pm
v2
Amit Kumar Tiwari 10-Mar-11 5:38am

Homework :D lol
I used to do this in 5th standard.
SAKryukov 10-Mar-11 5:40am

This is beyond the evil and the good...
You're probably at the wrong forum.
--SA
Ryan Zahra 10-Mar-11 5:43am

Before starting any code, you should learn to use google first. Good luck :)
AlbinAbel 10-Mar-11 7:09am

Area of a square and rectangle don't have different formula. That's what my teacher taught me at 5th standard. Why you want it separate

Rate this:

## Solution 1

then also seen below
```Program to calculate area of geometric figures.
#include<iostream.h>
#include<math.h>
void main()
{
char character;
double area;
cout<<"circle(c)
";
cout<<"square(s)
";
cout<<"rectangle(r)
";
cout<<"triangle(t)
";
cout<<"Select c,s,r or t:";
loop:
cin>>character;
if((character=='c')||(character=='C'))
{
double r;
const double pi=3.142;
cin>>r;
area=pi*pow(r,2);
}
else if((character=='s')||(character=='S'))
{
double l;
cout<<"Enter length:";
cin>>l;
area=pow(l,2);
}
else if((character=='r')||(character=='R'))
{
double l,w;
cout<<"Enter length:";
cin>>l;
cout<<"Enter width:";
cin>>w;
area=l*w;
}
else if((character=='t')||(character=='T'))
{
double b,h;
cout<<"Enter base:";
cin>>b;
cout<<"Enter height:";
cin>>h;
area=h*b/2;
}
else
{
cout<<"Select only c,s,r or t:";
goto loop;
}
cout<<"Area:"<<area<<endl;
}```
Amit Kumar Tiwari 10-Mar-11 5:43am

Outstanding my 5+ :)

Thanks you so much
AlbinAbel 10-Mar-11 7:10am

are the area of a square and rectangles have different formulae? Though the properties are different. New to me.
William Winner 10-Mar-11 12:21pm

Are you asking if you can calculate the area of a square differently than a rectangle? Of course you can. And of course, you can use the same equation as for a rectangle. A square is a rectangle with the same width and height, so instead of asking for width and height and multiplying them, you can just ask for one dimension and square it...as the author did here.
William Winner 10-Mar-11 12:20pm

Generally, we don't write people's homework for them. It would have been better to give them hints in the proper direction and/or asking more specific questions about what problems they are having.

Have you heard the phrase, "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

While it was very kind of you to provide the full code, you aren't really helping him by doing so.
Rate this:

## Solution 2

Well your solution is here - http://www.blurtit.com/q6427049.html[^]
princessdiane 10-Mar-11 20:08pm

do you have a C?
Rate this:

## Solution 3

Square = l^2
Rectangle = l*w
Circle = πr^2

What more do you need?

Just define the variables and apply the formulae.

Simples.
princessdiane 10-Mar-11 20:29pm

can you check if i have a mistake here. the answers are all zero

#include<stdio.h>

int l,wd,r,s;
double pi=3.14;

double Rectangle()
{
double rec;
rec=l*wd;
return(rec);
}

double Square()
{
double squ;
squ=s*s;
return(squ);
}

double Circle()
{
double cir;
cir=pi*(r*r);
return(cir);
}

void entry()
{
printf("Enter length\t: ");
scanf("%d",&l);
printf("Enter width\t: ");
scanf("%d",&wd);
scanf("%d",&r);
printf("Enter side\t: ");
scanf("%d",&s);
}

main()
{
double area;
clrscr();
entry();
printf("\n");
area=Rectangle();
printf("The area of Rectangle is : %g\n",area);
area=Square();
printf("The area of Square is\t : %g\n",area);
area=Circle();
printf("The area of Circle is\t : %g\n",area);
getch();
}

Top Experts
Last 24hrsThis month
 Jochen Arndt 140 Karthik Bangalore 135 OriginalGriff 110 Graeme_Grant 109 Bryian Tan 100
 OriginalGriff 5,741 RickZeeland 2,014 ppolymorphe 1,883 F-ES Sitecore 1,671 Dave Kreskowiak 1,494