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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>
using namespace std; // <--- Best not to use.
//validate input (I had to make this function return a value, because I didn't know how to save the variable otherwise if the person first put 0')
//void getRainFall(std::string county1, std::string county2, std::string county3, std::string month1, std::string month2, std::string month3, double &rainFall);
void getRainFall(string county1, county2, county3, string month1, month2 month3, double &rainFall);
// <--- Best to avoid global variables. Better put in "main" and pass to functions that need them.
double county 1 = St Lucie County;
double county 2 = Martin County;
double county 3 = Palm Beach County;
void findGreatestRainFall(std::string month1, std::string month2, std::string month3, double rainfall_1, double rainfall_2, double rainfall_3);
void findLeastRainFall(std::string month1, std::string month2, std::string month3,
double rainfall_1, double rainfall_2, double rainfall_3);
void welcome();
double rainSum(double rain1, double rain2, double rain3);
{
std::string month1 = month1;
double inches = rainfall;
if (inches <= 0)
{
while (inches <= 0)
{
cout << "Invalid inches input.... inches must be greater than 0 \n";
cout << "Please enter the rainfall in inches:";
cin >> inches;
cout << "\n";
}
}
return inches;
}
void findGreatestRainFall(std::string month1, std::string month2, std::string month3, double rainfall_1, double rainfall_2, double rainfall_3);
{
std::string month1 = month1;
std::string month2 = month2;
std::string month3 = month3;
double inches = rainfall_1;
double inches2 = rainfall_2;
double inches3 = rainfall_3;
if (inches < inches2 && inches < inches3)
{
std::cout << "********* The least amount of inches is: " << inches << " *********";
cout << "\n";
}
else if (inches2 < inches && inches2 < inches3)
{
std::cout << "********* Your least amount of rainfall inches is: " << inches2 << " *********";
cout << "\n";
}
else if (inches3 < inches && inches3 < inches2)
{
std::cout << "********* Your least amount of rainfall inches is: " << inches3 << " *********";
cout << "\n";
}
else if (inches == inches2 && inches == inches3)
{
printf("We have a 3 way TIE!! All the amounts are equal....");
cout << "\n";
}
else if (inches == inches2)
{
std::cout << "We have a TIE " << month1 << " and " << month2 << "Both amounts are equal...";
cout << "\n";
}
else if (inches == inches3)
{
std::cout << "We have a TIE " << month1 << " and " << month3 << " are equal!!!";
cout << "\n";
}
else if (inches2 == inches3)
{
std::cout << "We have a TIE " << month2 << " and " << month3 << " are equal!!!";
cout << "\n";
}
}
void findLeastRainFall(string m1, string m2, string m3,
double rf1, double rf2, double rf3);
{
std::string month1 = month1;
std::string month2 = month2;
std::string month3 = month3;
double inches = rainfall_1;
double inches2 = rainfall_2;
double inches3 = rainfall_3;
if (inches < inches2 && inches < inches3)
{
std::cout << "Yay! " << month1 << "is the least amount of rainfall";
cout << "\n";
}
else if (inches2 < inches && inches2 < inches3)
{
std::cout << "********* Your greatest number of rainfall inches is: " << inches2 << " *********";
cout << "\n";
}
else if (inches3 < inches && inches3 < inches2)
{
std::cout << "********* Your least amount of rainfall inches is: " << inches3 << " *********";
cout << "\n";
}
else if (inches == inches2 && inches == inches3)
{
printf("We have a 3 way TIE!! No greatest or least for this....");
cout << "\n";
}
else if (inches == inches2)
{
std::cout << "We have a TIE " << month1 << " and " << month2 << " are equal...";
cout << "\n";
std::cout << "********* Your tied number of rainfall inches is: " << inches << " *********";
cout << "\n";
}
else if (inches == inches3)
{
std::cout << "We have a TIE " << month << " and " << month3 << " are equal...";
cout << "\n";
std::cout << "********* Your tied number of rainfall inches is: " << inches << " *********";
cout << "\n";
}
else if (inches2 == inches3)
{
std::cout << "We have a TIE " << month2 << " and " << month3 << " are equal....";
cout << "\n";
std::cout << "********* Your tied number of rainfall inches is: " << inches2 << " *********";
cout << "\n";
}
}
void welcome()
for (int i = 0; i < 45; i++)
{
cout << "*";
}
cout << "\n";
cout << "Welcome to the Rainfall Program \n";
cout << "You will Enter the rainfall for the surrounding 3 counties and \n";
cout << "the month it occurred (the Rain Fall Must be > 0). \n";
cout << "\n";
cout << "Program Developed by: Koa \n";
{
cout << "*********************************************\n";
}
cout << "Please enter a real number for the rainfall in inches (the number must be > 0). \n";
for (int i = 0; i < 45; i++)
cout << "\n";
}
double rainSum(double rain1, double rain2, double rain3);
{
double sum = 0;
double inches = ti1;
double inches2 = ti2;
double inches3 = ti3;
return (inches + inches2 + inches3) / 3.0;
return sum;
}
int main()
{
//A. Declare and Initialize Variables to Store month’s(each county) Names(leasat), inches(greatest), and Average(sum)
std::string month = "Please enter the county's rainfall month: ";
std::string inches = "Please enter the month's rainfall in inches: ";
std::string month1, month2, month3;
double rainfall_1, rainfall_2, rainfall_3;
double sum;
std::string county1 = "St. Lucie County";
std::string county2 = "Martin County";
std::string county3 = "Palm Beach County";
//B. Call welcome() to display the program description
void welcome();
cout << month;
cin >> month1;
cout << "\n";
cout << inches;
cin >> rainfall_1;
//C. Call getRainFall() for St Lucie County
void getRainFall(county1, month1, rainfall_1);
cout << "\n";
cout << month;
//D. Call getRainFall() for Martin County
cin >> month2;
cout << "\n";
cout << inches;
cin >> rainfall_2;
//D. Call getRainFall() for Martin County
void getRainFall(county2, month2, rainfall_2);
cout << "\n";
cout << month;
cin >> month3;
cout << "\n";
cout << inches;
cin >> rainfall_3;
//E. Call getRainFall() for Palm Beach County
rainfall_3 = void getRainFall(month3, rainfall_3);
cout << "\n";
//F. Call findGreatestRainFall()
void findGreatestRainFall(month1, month2, month3, rainfall_1, rainfall_2, rainfall_3);
cout << "\n";
//G. Call findLeastRainFall()
void findLeastRainFall(month1, month2, month3, rainfall_1, rainfall_2, rainfall_3);
cout << "\n";
//H. Call rainSum() - Don't forget to capture the returned value
sum = double rainSum(rainfall_1, rainfall_2, rainfall_3);
cout << "Overall Average: " << avg;
cout << "\n";
return 0;
}
|