1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <iostream>
using namespace std;
//function prototypes
void getNumbers(int &, int &, int &);
void showMax(int);
int Findlargest (int, int, int);
int main () {
int no1, no2, no3, maxOf3; // Local variables are defined inside { }
// Local variables are used only in { }
getNumbers(no1, no2, no3);
maxOf3 = Findlargest(no1, no2, no3);
showMax(maxOf3);
return 0;
}
// A function that gets three numbers from the user.
void getNumbers(int &one, int &two, int &three){
cout<<"Enter 3 integers: ";
cin >> one >> two >> three;
cout << endl;
}
// A function displays the largest number among the
// three input numbers.
void showMax(int someNumber) {
cout << someNumber << " is the largest";
}
// A subprogram that finds the largest one and place it in Max.
int FindLargest (int no1, int no2, int no3){
int max;
if ((no1 > no2) && (no1 > no3))
max = no1;
else if (no2 > no3)
max = no2;
else
max = no3;
return max;
}
|