Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Need some functions help "C++"

Name: Anonymous 2007-03-10 6:56 ID:97+75dZh

I just wan't to know why dosn't my program gives me zero for my perimeter and area

#include<iostream> // for cout and cin
#include<cmath>

using namespace std;

int a,b,c,s,area;


void calc()
   {
    s=a+b+c;
    area=sqrt(s*(s-a)*(s-b)*(s-c));
    }

int main()
{    

     
      cout<<"Please enter the first side\n";
      cin>>a;
      cout<<"\nPlease enter the second side\n";
      cin>>b;
      cout<<"\nPlease enter the third side\n";
      cin>>c;
      //end part 1

Name: Anonymous 2007-03-10 12:14 ID:97+75dZh

here isz the problem

Lab 8 ( Chapter 6 Material )
The area of an arbitrary triangle can be calculated using the following formula:

                                   area = sqrt( s*(s-a)*(s-b)*(s-c) )

where a, b, and c are the lengths of the sides and s is the semiperimeter:

                                  s = ( a + b + c )/2

and, of course, sqrt() is the square root function accessible through the cmath header file.

Problem Statement
Write a function, call it ‘calc’, that has a ‘void’ return type and 5 parameters: a, b, c, &s, and &area. Your program should calculate the perimeter and area and store them in the reference parameters s and area.

Write a main function that prompts the user for a, b, and c. Your main() function should call ‘calc’ with the appropriate arguments.

NOTE: Your program should be robust, i.e., it should check to see that the values of a, b, and c entered by the user can, in fact, represent the sides of a triangle(see lab 6 discussion). Prior to calling ‘calc’, your main function should check to see that this condition is satisfied and display an error message if it is not satisfied.

Your output should be from the main function and should be in a form similar to that shown below, for a = 2, b = 2, c = 2:

        For a triangle of sides 2, 2, and 2,
         the perimeter is 6.000
         the area is 1.732

The area and perimeter should be given to a precision of 3 decimal places.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List