For my intro to C++ class we were recommended to create a program that checked for a maximum value and and average value. My question is, is there a more efficient want to check for a maximum value without creating more and more if statements? If I had 50 inputs for instance, would I have to make 49 if statements?
#include <iostream>
usingnamespace std;
int main()
{
constfloat INPUT_AMOUNT = 3.0;
short int1;
short int2;
short int3;
short max;
float avg;
cout << "Please enter the value of integer 1: " << endl;
cin >> int1;
cout << "Please enter the value of integer 2: " << endl;
cin >> int2;
cout << "Please enter the value of int 3: " << endl;
cin >> int3;
if (int1 > int2)
max = int1;
else
max = int2;
if (int3 > max)
max = int3;
avg = (static_cast<float>((int1 + int2 + int3) / INPUT_AMOUNT));
cout << avg << endl;
cout << max << endl;
return 0;
}