I am fairly new to programming and I wanted to see if this was an efficient way to write a program to solve for lowest number out of 3 using a function. I could not think of more efficient way with what I have learned thus far.
#include <iostream>
using namespace std;
float SmallestNum( float a, float b, float c)
{
if ((a <= c) && (a <= b))
{
float min;
min = a;
return min;
}
else if ((b <= c) && (b <= a))
{
float min;
min = b;
return min;
}
else if ((c <= b) && (c <= a))
{
float min;
min = c;
return min;
}
}
int main()
{
float a, b, c, z;
cout << "Please enter 3 seperate numbers : " << endl << endl;
cout << "1st: ";
cin >> a;
cout << "2nd: ";
cin >> b;
cout << "3rd: ";
cin >> c;
cout << endl << endl;
z = SmallestNum(a,b,c);
cout << z << " is your lowest number" << endl;
cout << endl;
system("pause");
return 0;
}