(Quiz 4) Minimum and double of bla bla bla

The quiz today, #quiz4, was to run a program where the user inputs three numbers (x, y and z) and give you the minimum number and the sum of its squares. We didn’t use any library like the last quiz, but we used functions. These was to return the minimum and the result of the sum.

Here is the code:

And here as well:

#include <iostream>
using namespace std;

int minimunThree (int, int, int);
int sumSquares (int, int, int);
int main () {
int x, y, z, m, ss;
cout << “Please give me x: “;
cin >> x;
cout << “Please give me y: “;
cin >> y;
cout << “Please give me z: “;
cin >> z;
m = minimunThree (x, y, z);
ss = sumSquares (x, y, z);
cout << endl << “The minimum number is: ” << m << endl;
cout << “The sum of squares is: ” << ss;
return 0;
}
int minimunThree (int x, int y, int z) {
int rm;
if (x < y && x < z) {
rm = x;
}
else if (y < x && y < z) {
rm = y;
}
else if (z < x && z < y) {
rm = z;
}
return rm;
}
int sumSquares (int x, int y, int z) {
int sx, sy, sz, rs;
sx = x * x;
sy = y * y;
sz = z * z;
rs = sx + sy + sz;
return rs;
}

The result is like this:

Please give me x: 9
Please give me y: 4
Please give me z: 12

The minimum number is: 4
The sum of squares is: 241

This covers #Mastery12. If you have any doubts, don’t hesitate in asking.

Leave a comment