#include <iostream> #include <cmath> #include <iomanip> using namespace std; class Triangle { private: double area; double side1, side2, side3; public: Triangle() { side1, side2, side3 = 0.0; } Triangle(double a, double b, double c) { side1 = a, side2 = b, side3 = c; } void setsides(double a, double b, double c) { side1 = a, side2 = b, side3 = c; } void calarea() { double s = (side1 + side2 + side3) / 2; area = sqrt(s*(s - side1)*(s - side2)*(s - side3)); } double getarea() { return area; } }; void main() { double s1, s2, s3; int n; int i; double max = 0; int maxindex = 0; Triangle arr[10]; cout << "Enter the number of triangles in range 1:10: "; cin >> n; for (i = 1; i < n + 1; i++) { cout << "\nEnter the sides triangle " << i << ": \n"; cin >> s1 >> s2 >> s3; arr[i].setsides(s1, s2, s3); arr[i].calarea(); arr[i].getarea(); } for (i = 1; i < n + 1; i++) { cout << "Area of triangle " << i << " is: " << setprecision(2) << fixed << arr[i].getarea() << "\n"; } for (i = 1; i < n + 1; i++) { if (arr[i].getarea() > max) { max = arr[i].getarea(); maxindex++; } cout << "\nThe largest area " << max << " is of triangle " << maxindex << endl; } } I know how to get the maximum value, but don't know how to get the position of the max value "without using algorithm or vector". There is one rule, if there are two same maximum value, we take the former one's position.
For example,
Area of triangle 1 is: 1.98 Area of triangle 2 is: 6.00 Area of triangle 3 is: 6.00 Area of triangle 4 is: 2.83 The largest area 6.00 is of triangle 2