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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <iomanip>
using namespace std;
#define LOWERRANGE -100.00
#define UPPERRANGE 100.00
void doRange(double);
double getReal(string, double, double);
int main()
{
doRange(4);
cout << endl << endl;
return 0;
}
double getReal(string prompt, double LOWERRANGE, double UPPERRANGE)
{
double num6, num7, num8, num9;
cout << "Enter the first real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
cin >> num6;
cout << "Enter the second real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
cin >> num7;
cout << "Enter the third real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
cin >> num8;
cout << "Enter the fourth real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
cin >> num9;
if(num6 < num7 && num6 < num8 && num6 < num9 && num7 > num8 && num7 > num9) //num7 will be the largest number and num6 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7 - num6; //smallest number will be subtracted from the largest number
}
else if(num6 < num7 && num6 < num8 && num6 < num9 && num8 > num7 && num8 > num9) //num8 will be the largest number and num6 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8 - num6;
}
else if(num6 < num7 && num6 < num8 && num6 < num9 && num9 > num7 && num9 > num8) //num9 will be the largest number and num6 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9 - num6;
}
else if(num7 < num6 && num7 < num8 && num7 < num9 && num6 > num8 && num6 > num9) //num6 will be the largest number and num7 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6 - num7;
}
else if(num7 < num6 && num7 < num8 && num7 < num9 && num8 > num6 && num8 > num9) //num8 will be the largst number and num7 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8 - num7;
}
else if(num7 < num6 && num7 < num8 && num7 < num9 && num9 > num6 && num9 > num8) //num9 will be the largest number and num7 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9 - num7;
}
else if(num8 < num6 && num8 < num7 && num8 < num9 && num6 > num7 && num6 > num9) //num6 will be the largest number and num8 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6 - num8;
}
else if(num8 < num6 && num8 < num7 && num8 < num9 && num7 > num6 && num7 > num9) //num7 will be the largest number and num8 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7 - num8;
}
else if(num8 < num6 && num8 < num7 && num8 < num9 && num9 > num6 && num9 > num7) //num9 will be the largest number and num8 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9 - num8;
}
else if(num9 < num6 && num9 < num7 && num9 < num8 && num6 > num7 && num6 > num8) //num6 will be the largest number and num9 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6 - num9;
}
else if(num9 < num6 && num9 < num7 && num9 < num8 && num7 > num6 && num7 > num8) //num7 will be the largest number and num9 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7 - num9;
}
else if(num9 < num6 && num9 < num7 && num9 < num8 && num8 > num6 && num8 > num7) //num8 will be the largest number and num9 will be the smallest
{
cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
<< " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
<< " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8 - num9;
}
return num6, num7, num8,num9;
}
| |