C++ Help

closed account (G2zhRXSz)
ANY help would be greatly appreciated!!!! I have been trying to figure this program out for the past couple days. I am a very new coder and in desperate need of help. I tried using a similar program I made in the past as a sort of template and ended up even more confused.

The instructions are as follows:

Write a program that allows you to enter the total rainfall in inches for St. Lucie County, Martin
County and Palm Beach County of Florida and the month of the recorded rain fall. Your program will
determine which counties had the same month of rainfall recorded and report back which county
had the greatest rain fall and the least amount of rainfall. If none of the rainfall recorded was within
the same month the program will output that the rainfall recorded is not all from the same month,
output all the months that the rain was recorded but still output the greatest rainfall, the month it
occurred. If the rainfall is equivalent in all three counties it must output this in the greatest rainfall
function. Next the program will output the least amount of and the month it occurred using the
same constraints as the greatest rainfall but will not output if they are equivalent (see sample
functions below). In addition, the program will also output the total rain fall for all counties. Your
program MUST validate the rain fall value input by the user (see Input Validation below). Your
program must use the functions described in the constraints below.

The program must check to see if the user enters a valid total rain fall. A number
greater than zero must be entered (Non-Zero/Non-Negative number). If the user does not enter a
valid value, display an error message and continue to ask the user to enter the value again until a
valid value is entered.

This is my pseudo code for the main function:
A. Declare and Initialize Variables to Store Rainfall for each county, least, greatest, and sum
B. Call welcome() to display the program description
C. Call getRainFall () for St Lucie County
D. Call getRainFall () for Martin County
E. Call getRainFall () for Palm Beach County
F. Call findGreatestRainFall ()
G. Call findLeastRainFall ()
H. Call rainSum () - Don't forget to capture the returned value
I. Output the Sum in main

These are the constraints I was given:
NO GLOBAL VARIABLES ALLOWED.
• You must use: int main()
• No Arrays or Vectors
• The program must use local variables.
• All functions MUST be called by main.
• This program MUST use the following functions:

Last but not least these are the names I was given to name the functions:
void getRainFall (string , string &, double &) - (3 pts) is passed the county name by value, the
name of the month by reference and the total rain fall for that county by reference. This
function must ask the user for the month and the total rain fall for that month. You must
validate the input for the total rain fall (See Input Validation above). This function returns no
value.
void findGreatestRainFall (string, string, string, double , double , double) - is passed
the three months names and the three rain fall totals by value and returns no value. This
function must determine which county had the greatest rainfall and output the month with
the greatest rain fall. The function must check to see if each county reported the rainfall for
the same month. If the recorded rainfall is from the same month for all three counties, then
the program will output the month and the greatest rainfall. If all the recorded rainfall is not
within the same month it must output each month and output the greatest rainfall along
with the month it occurred. If all counties had the same rainfall then the program must
output, “rainfall in all counties are equivalent”.
void findLeastRainFall (string, string, string, double , double , double) - (3 pts) is passed the
three months names and the three rain fall totals by value and returns no value. This
function must determine which county had the least rainfall and output the month with the
least rain fall. The function must check to see if each county reported the rainfall within the
same month. If the recorded rainfall is from the same month for all three counties, then the
program will output the month and the least rainfall. If not within the same month it must
output each month and output the least rainfall along with the month it occurred. If all
counties had the same rain fall then the program will not output a smallest value but a
message, “no lowest rainfall”.
void welcome() - is NOT passed any values and returns no value. This function
outputs a description of the program and the developer's name (i.e. YOUR name). Your
function MUST display the following text and fill in your name as the developer's name.
*****************************************************************
Welcome to the Rain Fall Program
You will enter the rainfall for the surrounding 3 counties and the month
it occurred (the Rain Fall Must be > 0).
Program Developed by: "PUT YOUR NAME HERE"
*****************************************************************
double rainSum (double , double , double) - The three rain fall totals are passed to
this function and the function sums the three rain fall totals, the sum calculation is then
RETURNED to main. The sum result is then OUPUT in the main function.


Thank you so much to anyone who is able to help!! I am very new at this and am really struggling. I will put my code that I have so far in the comments!
Last edited on
closed account (G2zhRXSz)
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>
using namespace std;

//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(string county1, county2, county3, string month1, month2 month3, double &rainFall);
double county 1 = St Lucie County
double county 2 = Martin County
double county 3 = Palm Beach County
void findGreatestRainFall (string month1, string month2, string month3,
double rainfall_1, double rainfall_2 , double rainfall_3);
void findLeastRainFall (string month1, string month2, string month3,
double rainfall_1, double rainfall_2 , double rainfall_3);
void welcome();
double rainSum(double rain1, double rain2, double rain3);
{
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 (string m1, string m2, string m3,
double rf1, double rf2 , double rf3);
{
string month1 = month1;
string month2 = month2;
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);
{
string month1 = month1;
string month2 = month2;
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)
string month = "Please enter the county's rainfall month: ";
string inches = "Please enter the month's rainfall in inches: ";

string month1, month2, month3;
double rainfall_1, rainfall_2, rainfall_3;
double sum;
string county1 = "St. Lucie County";
string county2 = "Martin County";
string county3 = "Palm Beach County";
//B. Call welcome() to display the program description
welcome();

cout << month;
cin >> month1;
cout << "\n";

cout << inches;
cin >> rainfall_1;
//C. Call getRainFall() for St Lucie County
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

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 = getRainFall(month3, rainfall_3);

cout << "\n";

//F. Call findGreatestRainFall()
findGreatestRainFall(month1, month2, month3, rainfall_1, rainfall_2, rainfall_3 );
cout << "\n";

//G. Call findLeastRainFall()
findLeastRainFall(month1, month2, month3, rainfall_1, rainfall_2, rainfall_3 );
cout << "\n";

//H. Call rainSum() - Don't forget to capture the returned value
sum = rainSum(rainfall_1, rainfall_2, rainfall_3);


cout << "Overall Average: " << avg;
cout << "\n";

return 0;

}
Topic archived. No new replies allowed.