Q:

C++ Using if/else statements in function definition to return smallest number

For my homework assignment in C++, my goal is to write a program the inputs three integers and passes them to a function that returns the smallest number. This is only my 3rd week of C++, so I don't know much.
In addition, I'm only allowed to start off with #include<iostream> and using namespace std. I had been at this for hours,this just doesn't come easy to me. I've tried so many different things and I've only been getting errors...
This is the code I have so far that I actually understand:
#include <iostream>
using namespace std;

int fsmallestNumber(int);

int main() {
    int numberOne;
    int numberTwo;
    int numberThree;
    int smallestNumber;

    cout << "Enter in 3 numbers and I will find the smallest of all three" << endl;
    cin >> numberOne >> numberTwo >> numberThree;

    cout << "The smallest of all three numbers is " << smallestNumber << endl;

}

int fsmallestNumber(int sn){

}

I'm confused on how to use the if/else statements to find the smallest number, and how to return the smallest number back into the function to print it out.

A:

Here you are.
#include <iostream>

using namespace std;

int fsmallestNumber( int, int, int );

int main() 
{
    int numberOne;
    int numberTwo;
    int numberThree;
    int smallestNumber;

    cout << "Enter in 3 numbers and I will find the smallest of all three" << endl;
    cin >> numberOne >> numberTwo >> numberThree;

    smallestNumber = fsmallestNumber( numberOne, numberTwo, numberThree );

    cout << "The smallest of all three numbers is " << smallestNumber << endl;
}

int fsmallestNumber( int x, int y, int z )
{
    int smallest = x;

    if ( y < smallest ) smallest = y;
    if ( z < smallest ) smallest = z;

    return smallest;
}

The function has to accept three arguments. So it must be declared with three parameters.
If you need to include an else statement then the function can be written like
int fsmallestNumber( int x, int y, int z )
{
    int smallest;

    if ( not ( y < x || z < x ) )
    {
        smallest = x;
    }
    else if ( not ( z < y ) )
    {
        smallest = y;
    }
    else
    {
        smallest = z;
    }

    return smallest;
}

Pay attention to that the C++ standard library already has suitable algorithm std::min declared in the header <algorithm>. So you could just write
#include <algorithm>

//...

smallestNumber = std::min( { numberOne, numberTwo, numberThree } );

