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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#include <iostream>
#include <iomanip>
using namespace std;
void welcome();
void getBabyWeight(double &, double &, double &, double &, double &);
void findLowest(double &, double &, double &, double &, double &);
void findHighest(double &, double &, double &, double &, double &);
//void weightAverage(double &, double &, double &, double &, double &);
double weightAverage(double &, double &, double &, double &, double &);
int main()
{
double baby1, baby2, baby3, baby4, baby5, average;
cout << fixed << showpoint << setprecision(2);
welcome();
getBabyWeight(baby1, baby2, baby3, baby4, baby5);
findLowest(baby1, baby2, baby3, baby4, baby5);
findHighest(baby1, baby2, baby3, baby4, baby5);
//weightAverage(baby1, baby2, baby3, baby4, baby5);
average = weightAverage(baby1, baby2, baby3, baby4, baby5);
cout << endl << "Today's average weight is " << average << endl;
}
void welcome()
{
cout << "***************************************";
cout << endl << "BABY WEIGHT PROGRAM" << endl;
cout << "Please enter the Five Baby Weights" << endl;
cout << "Please enter a real number Weights (Must be >0)." << endl;
cout << endl << "Program Developed by: Rohan S. Jakhete" << endl;
cout << "***************************************";
}
void getBabyWeight(double &baby1, double &baby2, double &baby3, double &baby4, double &baby5)
{
cout << endl << "Please enter the values now";
cin >> baby1;
while (baby1 <= 0)
{
cout << "Invalid weight...weight must be greater than 0";
cin >> baby1;
}
cin >> baby2;
while (baby2 <= 0)
{
cout << "Invalid weight...weight must be greater than 0";
cin >> baby2;
}
cin >> baby3;
while (baby3 <= 0)
{
cout << "Invalid weight...weight must be greater than 0";
cin >> baby3;
}
cin >> baby4;
while (baby4 <= 0)
{
cout << "Invalid weight...weight must be greater than 0";
cin >> baby4;
}
cin >> baby5;
while (baby5 <= 0)
{
cout << "Invalid weight...weight must be greater than 0";
cin >> baby5;
}
}
void findLowest(double &baby1, double &baby2, double &baby3, double &baby4, double &baby5)
{
if ((baby1 < baby2) && (baby1 < baby3) && (baby1 < baby4) && (baby1 < baby5)) {
cout << endl << "Baby 1 has the lowest weight at " << baby1;
}
else if ((baby2 < baby1) && (baby2 < baby3) && (baby2 < baby4) && (baby2 < baby5)) {
cout << endl << "Baby 2 has the lowest weight at " << baby2;
}
else if ((baby3 < baby1) && (baby3 < baby2) && (baby3 < baby4) && (baby3 < baby5)) {
cout << endl << "Baby 3 has the lowest weight at " << baby3;
}
else if ((baby4 < baby1) && (baby4 < baby2) && (baby4 < baby3) && (baby4 < baby5)) {
cout << endl << "Baby 4 has the lowest weight at " << baby4;
}
else if ((baby5 < baby1) && (baby5 < baby2) && (baby5 < baby3) && (baby5 < baby4)) {
cout << endl << "Baby 5 has the lowest weight at " << baby5;
}
else
{
cout << endl << "There is a tie!! No lowest baby weight today";
}
}
void findHighest(double &baby1, double &baby2, double &baby3, double &baby4, double &baby5)
{
if ((baby1 > baby2) && (baby1 > baby3) && (baby1 > baby4) && (baby1 > baby5)) {
cout << endl << "Baby 1 has the highest weight at " << baby1;
}
else if ((baby2 > baby1) && (baby2 > baby3) && (baby2 > baby4) && (baby2 > baby5)) {
cout << endl << "Baby 2 has the highest weight at " << baby2;
}
else if ((baby3 > baby1) && (baby3 > baby2) && (baby3 > baby4) && (baby3 > baby5)) {
cout << endl << "Baby 3 has the highest weight at " << baby3;
}
else if ((baby4 > baby1) && (baby4 > baby2) && (baby4 > baby3) && (baby4 > baby5)) {
cout << endl << "Baby 4 has the highest weight at " << baby4;
}
else if ((baby5 > baby1) && (baby5 > baby2) && (baby5 > baby3) && (baby5 > baby4)) {
cout << endl << "Baby 5 has the highest weight at " << baby5;
}
else
{
cout << endl << "There is a tie!! No highest baby weight today";
}
}
//void weightAverage(double &baby1, double &baby2, double &baby3, double &baby4, double &baby5)
//{
// double average;
// average = (baby1 + baby2 + baby3 + baby4 + baby5) / 5;
//
//}
double weightAverage(double &baby1, double &baby2, double &baby3, double &baby4, double &baby5)
{
double average;
average = (baby1 + baby2 + baby3 + baby4 + baby5) / 5;
return average;
}
| |