Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double  bignumber(double num1, double num2);  //Declares the function 'bignumber'
  5. double  smallnumber(double num1, double num2);//Declares the function 'smallnumber'
  6. void main()
  7. {
  8.     double num1; //Holds the 1st number
  9.     double num2;//Holds the 2nd number
  10.     double num3;//Holds the 3rd number
  11.     double bignum; //Holds the biggest number out of the 3 numbers
  12.     double smallnum; //Holds the smallest number out of the 3 numbers
  13.  
  14.     cout << "Please enter three numbers: ";
  15.     cin >> num1 >> num2 >> num3;
  16.  
  17.     bignum = bignumber(num1, num2); //Call to function 'bignumber'
  18.     bignum = bignumber(bignum, num3); //Call to function 'bignumber'
  19.  
  20.     cout << "The biggest number amongst the 3 numbers you've entered is: " << bignum << endl;
  21.  
  22.     smallnum = smallnumber(num1, num2); //Call to function 'smallnumber'
  23.     smallnum = smallnumber(smallnum, num3); //Call to function 'smallnumber'
  24.  
  25.     cout << "The smallest number amongst the 3 numbers you've entered is: " << smallnum << endl;
  26.  
  27. }
  28.  
  29.  
  30. double bignumber(double num1, double num2) //This function will find the biggest of the two numbers
  31. {
  32.  
  33.     if ((num1 - num2)>=0) //Checks if num1-num2 is a non-negative number, therefor num1 is bigger or equal to num2
  34.     {
  35.         return(num1);
  36.  
  37.     }
  38.  
  39.     if ((num1 - num2)<0) //Checks if num1-num2 is a negative number, therefor num2 is bigger than num1
  40.     {
  41.         return(num2);
  42.     }
  43.  
  44. }
  45.  
  46. double  smallnumber(double num1, double num2) //This function will find the smallest of the two numbers
  47. {
  48.     if ((num1 - num2) >= 0) //Checks if num1-num2 is a non-negative number, therefor num2 is smaller or equal to num1
  49.     {
  50.         return(num2);
  51.  
  52.     }
  53.  
  54.     if ((num1 - num2)<0) //Checks if num1-num2 is a negative number, therefor num1 is smaller than num2
  55.     {
  56.         return(num1);
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement