# Simple Area and Triangle Functions

Page 1 of 1

## 1 Replies - 2161 Views - Last Post: 05 February 2012 - 09:19 AM

### #1 athlon32 Reputation: 117
• Posts: 363
• Joined: 20-August 08

# Simple Area and Triangle Functions

Posted 10 October 2009 - 04:29 PM

Description: In Visual C++ press F7 :PGives three functions for areas, and one on getting the measure third angle of a triangle. BTW, I suck at math, so sorry if there's some errors in the formulas :P
```// just some math

#include <iostream>

int triArea(unsigned int &base, unsigned int &height)
{
int area = (base/2)*height;
return area;
}

int squArea(unsigned int &base, unsigned int &height)
{
int area = base*height;
return area;
}

{
return area;
}

int missingAngle(unsigned int &angle1, unsigned int &angle2)
{
int angle3 = ((180 - angle1)-angle2);
return angle3;
}

int main()
{
unsigned int x, y;
x = 5;
y = 6;

std::cout << "The area of the triangle is " << triArea(x, y) << std::endl;
std::cout << "The area of the square is " << squArea(x, y) << std::endl;
std::cout << "The area of the circle is " << cirArea(x) << std::endl;

unsigned int anglex, angley;
anglex = 50;
angley = 90;

std::cout << "The Third Angle is " << missingAngle(anglex, angley) << " degrees";
return 0;
}

```

Is This A Good Question/Topic? 0

## Replies To: Simple Area and Triangle Functions

### #2 Karel-Lodewijk Reputation: 455
• Posts: 864
• Joined: 17-March 11

## Re: Simple Area and Triangle Functions

Posted 05 February 2012 - 09:19 AM

The triArea function will go wrong because the area of a triangle with an integer base and height is not necessarily an integer. Even when it is, if base is not evenly dividable by 2, then the result will be wrong. Please fix.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }