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:
Anonymous2007-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";
}
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:
Anonymous2007-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:
Anonymous2007-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:
Anonymous2007-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.
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:
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