define a function that ask a user to enter three numbers and program display the largest using function with return value and argument
#include <iostream>
using namespace std;
double Largest();
int main() {
cout<<"Largest: "<< Largest();
cout<<endl;
return 0;
}
double Largest(){
double n1,n2,n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
return n1;
if(n2 >= n1 && n2 >= n3)
return n2;
if(n3 >= n1 && n3 >= n2)
return n3;
}
Comments
Leave a comment