1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <cmath>
using namespace std;
void inputSides();
void area(int semiperimeter, int sideA, int sideB, int sideC);
void perimeter(int sideA, int sideB, int sideC);
void semiperimeter(int sideA, int sideB, int sideC);
void conditions(int sideA, int sideB, int sideC, int area, int perimeter);
void output(int area, int perimeter);
int main()
{
char input = 'y';
while (input == 'y') {
inputSides();
cout << "Enter y to repeat, any other key to quit " << endl;
cin >> input;
}
}
void inputSides() {
int sideA;
int sideB;
int sideC;
int semiperimeter;
cout << "Enter a positive number for side A: " << endl;
cin >> sideA;
cout << "Enter a positive number for side B: " << endl;
cin >> sideB;
cout << "Enter a positive number for side C: " << endl;
cin >> sideC;
perimeter(sideA, sideB, sideC);
area(semiperimeter, sideA, sideB, sideC);
}
void area(int semiperimeter, int sideA, int sideB, int sideC) {
void area = sqrt((semiperimeter - sideA) * (semiperimeter - sideB) * (semiperimeter - sideC)); //incomplete type is not allowed, and 'area': illegal use of type 'void'
}
void semiperimeter(int sideA, int sideB, int sideC) {
int semiperimeter = (sideA + sideB + sideC) / 2;
}
void perimeter(int sideA, int sideB, int sideC) {
void perimeter = sideA + sideB + sideC; //incomplete type is not allowed, and 'perimeter': illegal use of type 'void;
}
void conditions(int sideA, int sideB, int sideC, int area, int perimeter) {
if ((sideA + sideB > sideC) && (sideB + sideC > sideA)) {
output(area, perimeter);
if ((sideA + sideB > sideC) && (sideA + sideC > sideB))
output(area, perimeter);
if ((sideB + sideC > sideA) && (sideA + sideC > sideB))
output(area, perimeter);
if ((sideB + sideC > sideA) && (sideA + sideC > sideB));
else {
cout << "Not a triangle." << endl;
}
}
}
void output(int area, int perimeter) {
cout << "Area is: " << area << endl;
cout << "Perimeter is: " << perimeter << endl;
}
|