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

#1 athlon32   User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • 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;
}

double cirArea(unsigned int &radius)
{
  double area = 2*(3.14 *(radius*radius));
  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   User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1