Today I did the quiz #4in which I needed to do a program that asked the user for 3 integers and then returned the smallest integer and the sum of squares of the three of them.

First I did the function to find the smallest value, what I did was import a library called “algorithm”, where I could use the function “min” that returns the smaller value between two values, but because I had three values I used the “min” function two times as you can see in the code (to get the min between two numbers and then get the min between the other number and the result of the first min.). I learned this method because I googled it, thanks to this page:

http://stackoverflow.com/questions/9424173/c-find-the-smallest-amongst-3-numbers

The I imported another library called “cmath” that allows me to use the function “pow”, so in the second function to calculate the sum of squares I wrote pow 2 for each value (x, y and z) and then I added the results of the pow.

Here’s my code:

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int minimumThree(int x, int y, int z){
return min(x, min(y, z));
}
int sumSquares( int x, int y, int z){
return pow(x,2)+ pow(y,2)+ pow(z,2);
}

int main ()
{
int x, y, z;
cout<< “I’m going to calculate the sum of squares of three numbers.”<<endl;
cout<< “And I’ll tell you which one of those three numbers is the smallest.”<<endl;
cout<<“Please give me the first number:”<<endl;
cin>> x;
cout<< “Please give me the second number:”<<endl;
cin>> y;
cout<<“Please give me the third number:”<<endl;
cin>> z;
cout<< “The minimum is: “<< minimumThree(x, y, z)<<endl;
cout<< “The sum of squares is: “<<sumSquares(x, y, z)<<endl;

return 0;
}

screen-shot-2017-02-02-at-3-23-27-pmscreen-shot-2017-02-02-at-3-24-22-pm