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

Pages: 1-

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 6:57 ID:97+75dZh

     
       //This will test the triangle and see if it is rigt or not
      if(a+b-c>=0 ||a+b-c>=0 ||a+b-c>=0)
      {
      cout<<"The triangle is true \n";
      void calc();
     
      cout<<"for the triangle of sides "<<a<<","<<b<<" and "<<c<<",\n";
      cout<<"the perimeter is "<<s<<"\n";
      cout<<"the area is "<<area<<"\n";
      }
     
      else
      {
      cout<<"Error: triangle doesn't exist \n";
      }
      system("pause") ;        
      return 0;

}

Name: Anonymous 2007-03-10 7:13 ID:9SdgIsVp

>>1

lrn2notuseglobalvariables, kthxbye

Name: Anonymous 2007-03-10 7:22 ID:pRyWeSyi

Bitches don't know about http://cpptutors.on.nimp.org

Name: Anonymous 2007-03-10 7:26 ID:vXV/Cixf

The problem is the statement void calc(); in your main() function. This statement isn't a call to the calc() function like you want it to be. It is a declaration of a function named calc returning void and having no parameters. To actually call calc() you need to use calc();

Name: Anonymous 2007-03-10 9:38 ID:r8htZT0z

/*
You suck! I'll rewrite your stuff because
I have a cigarette to smoke and some time to waste...

AND NO GLOBAL VARIABLES, 0xN00B!
*/

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <cmath>

inline int area(const int a, const int b, const int c) {
    int s = a+b+c;
    return ::sqrt(s*(s-a)*(s-b)*(s-c));
}

inline int perimeter(const int a, const int b, const int c) {
    return a+b+c;
}

int main() {
    int a, b, c;
   
    cout << "Enter first side: ";
    cin >> a;
   
    cout << "Enter second side: ";
    cin >> b;
   
    cout << "Enter third side: ";
    cin >> c;
   
    if ((a+b-c) >= 0) {
        cout << "The triangle is true (whatever that means)."
   
        cout << "With sides " << a << ", " << b << ", and " << c << endl;
        cout << "Perimeter: " << perimeter(a, b, c) << endl;
        cout << "Area: " << area(a, b, c) << endl;
    } else
        throw 42;
}

Name: Anonymous 2007-03-10 11:42 ID:MZ5NLU33

#include <cmath>
#include <iostream>

class Triangle {
public:
  Triangle(int a, int b, int c) : itsSideA(a), itsSideB(b), itsSideC(c) {}
  ~Triangle() {}
  bool isRigt() const {
    //This will test the triangle and see if it is rigt or not
    if (itsSideA + itsSideB - itsSideC >= 0 || itsSideA + itsSideB - itsSideC >=0 || itsSideA + itsSideB - itsSideC >= 0) return true;
    return false;
  }
  int getPerimeter() const {
    return itsSideA + itsSideB + itsSideC;
  }
  double getArea() const {
    return std::sqrt(getPerimeter()*(getPerimeter()-itsSideA)*(getPerimeter()-itsSideB)*(getPerimeter()-itsSideC));
  }
private:
  int itsSideA;
  int itsSideB;
  int itsSideC;
};

int main() {
  int a, b, c;

  std::cout << "Please enter the first side\n";
  std::cin >> a;
  std::cout << "\nPlease enter the second side\n";
  std::cin >> b;
  std::cout << "\nPlease enter the third side\n";
  std::cin >> c;

  Triangle triangle(a, b, c);
  if (triangle.isRigt()) {
    std::cout << "The triangle is true \n";
    std::cout << "for the triangle of sides " << a << "," << b << " and " << c << ",\n";
    std::cout << "the perimeter is " << triangle.getPerimeter()<<"\n";
    std::cout << "the area is " << triangle.getArea()<<"\n";
  } else {
    std::cout << "Error: triangle doesn't exist \n";
  }
  return 0;
}

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.

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

So I still need to use void calc()

Name: Anonymous 2007-03-10 12:37 ID:Heaven

void sage()

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

I lold for some reson

Name: Seraph 2007-03-14 0:16 ID:2kBz29gw

>>9


perhaps use calc to, umm I dunno, retun an answer from based on parameters. Unless the assignment is: "Noob Coding 101: Assignment 3 - Using global variables and ignoring what your book/professor/intarweb/everyone has ever said about what the eff funtions are for" but im guessing its not. soo... pass things into  your function and make it non void, kinda like:

int calc(int a, int b, int c)

Name: Anonymous 2007-03-14 1:10 ID:Heaven

>>8
That reads like an exercise for the express purpose of teaching a person how to write functions that take/manipulate pointers... in C.

Name: Anonymous 2009-03-06 12:25


FastCGI not plain CGI Unless you want   to get the   HEROES THAT GAVE   THEIR TIME AND   it will change   this but I   think they removed   the color from.

Name: Anonymous 2009-08-16 17:10

else care to care to help to help. bump help. bump for bump for more for more mango more mango   gtfo mango   gtfo no gtfo no its no its not its not    fuck not    fuck #sicp fuck #sicp gtfo sicp gtfo   gtfo gtfo   gtfo  8 gtfo  8/10 8/10, not 10, not revealed

Name: Anonymous 2011-02-03 2:21

Name: Anonymous 2011-02-04 16:12

Name: Anonymous 2012-03-23 23:42

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

Name: Sgt.Kabu㕤莊kiman팺绪 2012-05-28 23:15

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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