Chapter 6 User defined Functions 1

Complete Program Listing

//Program: Largest

#include <iostream>

using namespace std;



double larger(double x, double y);



int main()

{

   double num; //variable to hold the current number

   double max; //variable to hold the larger number

   int count;  //loop control variable



   cout<<"Enter 10 numbers."<<endl;

   cin>>num;                                   //Step 1

   max = num;                                  //Step 1



   for(count = 1; count < 10; count++)         //Step 2

   {

      cin>>num;                                //Step 2a

      max = larger(max, num);                  //Step 2b

   }



   cout<<"The largest number is "<<max<<endl;  //Step 3



   return 0;

}//end main



double larger(double x, double y)

{

   if(x >= y)

      return x;

   else

      return y;

}

Sample Run: In this sample run, the user input is shaded.

Enter 10 numbers.



10 56 73 42 22 67 88 26 62 11



The largest number is 88