Please Help!!

closed account (G2zhRXSz)
Hey guys-
I wrote this code and am completely lost :( I can not use any arrays or vectors. Any help is greatly appreciated!!! My code is below, I just can't seem to figure out what I am doing wrong. Thank you!

It is supposed to look like this when run:
*****************************************************************
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: Koa
*****************************************************************

#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 month1, string month2, string month3, double rainfall_1, double rainfall_2 , double rainfall_3);
{
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
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;

}
Lemme guess....

You're a student, wrote this entire thing in the text editor, got some compiler errors and all but gave up on figuring out what it is telling you....

...'bout right?

Compilers differ in their messages and part of the task of programming is to understand what that means. It doesn't always say what it means, and it doesn't always point directly at the problem, exactly.

The first error my compiler tells me is "syntax error identifier county2. There's something wrong on the "void getRainFall" function declaration, and it's simple - and it's echoed several times.

The first parameter is declared as type string, the name of the parameter is county1.

The second parameter has not type, but the name is county2. That's the syntax error. There is no type. I assume it's a string, but that's up to your design. Notice county3, month2, month3 all have the same problem.

That's a start.

Look to the lines below it, though.

double count 1 = St Lucie County.

This has several problems. A double is a number, but St. Lucie County is a string (well, it looks like you intend it to be a string). I assume that means you intended a string, not a double.

Beyond that, there can be NO spaces in an identifier like county1, so remove the space.

Then, string literals must be enclosed in quotation marks, otherwise the compiler is trying to figure out what St Lucie County means as 3 words, but has no knowledge of them as any kind of keywords.

Once those are covered, compile again, and see what it says....fix the complaints and repeat until compiled.

It's a typical process, not at all unusual to have the compiler blast complaints like a firehose. I've seen over 50 complaints that was really do to a missing semicolon.

The task, therefore, is for you to become accustomed to this cycle of compile, read complaints, figure out why the compiler is complaining, fix that, and repeat.

We've all been through it. Many times. Me....40+ years.


Last edited on
I started to clean it up a bit which is exactly what your code needs more than anything. You are on the right track so that is the good news! Just little mistakes are tripping you up. It would help if I knew the directions or what is expected. Feel free to message me privately, I'm willing to help.

Here is the code I cleaned up:
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
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>
using namespace std;


void welcome();
void getRainFall(string &c1, string &c2, string &c3, string month1, string month2, string month3,double rainfall_1, double rainfall_2, double rainfall_3);
void findGreatestRainFall();
void findLeastRainFall();
double rainSum();

int main(){
    //A. Declare and Initialize Variables to Store month’s(each county) Names(least), inches(greatest), and Average(sum)   
    string month1, month2, month3;
    double rainfall_1, rainfall_2, rainfall_3, sum, leastRainfall, greatestRainfall;
    string county1 = "St. Lucie County";
    string county2 = "Martin County";
    string county3 = "Palm Beach County";
    

    //B. Call welcome() to display the program description
    welcome();
    
    
    //C. Call getRainFall() for St Lucie County
    //D. Call getRainFall() for Martin County
    //E. Call getRainFall() for Palm Beach County
    getRainFall(county1, county2, county3, month1, month2, month3,rainfall_1,rainfall_2,rainfall_3);
    
    //F. Call findGreatestRainFall()
    //findGreatestRainFall( );

    
    //G. Call findLeastRainFall()
   //findLeastRainFall();
    
    //H. Call rainSum() - Don't forget to capture the returned value
    //rainSum();


} 
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 << "Program Developed by: Koa \n";
    for(int i = 0; i < 45; i++) {
        cout << "*";
    }
    cout << "\n\n";


}
void getRainFall(string &c1, string &c2, string &c3, string month1, string month2, string month3, double rainfall_1, double rainfall_2, double rainfall_3){
    cout << "Enter the month of the rainfall for " << c1 << ": ";
    cin >> month1;
    cout << "Enter the amount of rainfall for " << c1 << "(in inches): ";
    cin >> rainfall_1;
    cout << "Enter the month of the rainfall  for " << c2 << ": ";
    cin >> month2;
    cout << "Enter the amount rainfall for " << c2 << "(in inches): ";
    cin >> rainfall_2;
    cout << "Enter the month of the rainfall  for " << c3 << ": ";
    cin >> month3;
    cout << "Enter the amount of rainfall for " << c3 << "(in inches):";
    cin >> rainfall_3;
    cout << endl;
}


As you will see, the code runs but it definitely isn't finished. Hope it at least helps.
One more point: when you get syntax errors, always start with the first error. Sometimes the first error throws off the parser, causing it to generate tons of error messages for things that will all be fixed by that first error.

Some other common errors:

- when defining a function, you don't put a semicolon between the closing parenthesis and the opening brace:
1
2
3
4
void foo(int i, int j) // <<-- no semicolon here
{
   stuff
}


When calling a function, you don't give the function's type:
void getRainFall(county1, month1, rainfall_1); // <<-- remove "void" at the beginning

Your rainSum() function actually returns the average. Decide if you want it to compute the sum or the average and name it accordingly.
Hello koaken,

Because it made one message so long I had to break this up into two parts. The following ereply will be refering to the line numbers of this code.

This is your code with a few blank lines added and some blank lines removed :
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;
}

Hello koaken,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.




Starting from the top:

Your "#include" files are OK with the exception of <stdio.h>. First you should use <ctddio> instead of the C header file. Not only should <iostream> cover any C statements you use like the "printf"s it is very likely that <iostream> will include <cstdio> along with some other <c?????> header files that you do not think about.

Next, line 6, the comment says it all.

The next section is your prototypes which you do well for the most part down to line 22. Line 22 is a good prototype, but you are trying to use it for the function definition. This does not work.

You may need to reread your text book on functions or have a look at http://www.cplusplus.com/doc/tutorial/functions/

Putting your functions above "main" can work, but there ate times that the order of the functions can make a big difference and that is where the prototypes help.

You have
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}

Line "1" is a prototype in the wrong place and lines 2 - 18 make up the function body that has no function definition. The semicolon at the end of line "1" makes it a prototype not a function definition.

And the same goes for the bits of code that you are trying to call functions.

In what should be the function "findGreatestRainFall" you have
1
2
std::cout << "********* The least amount of inches is: " << inches << " *********";
cout << "\n";

Choose on or the other. It is not a problem, but does not look good when you use both. Personally I would suggest using std::cout.

Then you have
1
2
printf("We have a 3 way TIE!! All the amounts are equal....");
cout << "\n";

Of the two I would stay with the std::cout statements as it more proper C++ code.

I back up a bit here. Lines13 - 15 are global veriables that are best not used as global variables. It is better to define them in "main" and pass them to the functions that need them.

As global variables any function in the file has the ability to change their values and this can make finding where the problem is more difficult.

As both Niccolo and racs24 have pointed out the problems with whht you have. Also burring these variables in the middle of the prototypes is not a good idea because it tends to hide them and make them harder to find.

I also noticed that in "main" you used the correct variable type when you defined the variables "county1", "county2" and "county3". Which makes your global variables unused because you used a different variable name that does not work. When I removed them from the program it caused no problem.

The function "welcome" is prototyped correctly and the function is defined correctly, but you forgot the opening {.

Inside "main" you have likes like void getRainFall(county1, month1, rainfall_1);. This makes a nice prototype, but is not a function call. Here "void" makes it a prototype.

At this point until I fix all the errors and can get the program to compile I have not looked at what it is actually doing. I will know more once ai get ti to run.

Hope that helps,

Andy
I'll say that it would be easier to write it from scratch.
work by small increments, write a function, make it compile and test it.
and write it yourself, don't let others touch your keyboard or start copying snips from anywhere.
@ne555,

After working with the program for awhile he should not only start over, but plan out the program first.

Have a close look at the functions "findGreatestRainFall" and "findLeastRainFall" especially the parameters.

For functions that should be similar they are very different.

@koaken,

Your code is poorly planned if planned at all.

You define a prototype for "getRainFall", but do not define the function. This is easily made a generic function. By passing the county name, month name, and the variable for "rainFall", (by reference), you can design a nice prompt to get the amount of rainfall.

When I worked on "findGreatestRainFall" I first had to make some changes and noticed the output messages are for the least amount of rain.

When I started to work on "findLeastRainFall" I found that it is so different from the other function I had to take a break because I keep coming back to thinking about how the program should be written and not how to fix what you have, which could be fixed given enough time and some rework.

Another thing that kept bothering me is that you are allowing the opportunity to enter different months for each county. This could end up comparing January's snow fall to July's rainfall. That is not a good idea. The month should be entered once not three times.

As ne555 suggested I think I will start over with a more thought out approach. Keep the original code as some of it is still useful.

Hope that helps,

Andy
closed account (G2zhRXSz)
Thank you guys so much for all your help. I took a lot of your advice and started rewriting it from scratch. I am stuck on the function definitions. Anyone have any ideas? My code is below:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
/*FUNCTION PROTOTYPING*/
void getRainFall (string countyname , string &monthname, double &rainFall);
void findGreatestRainFall (string month1, string month2, string month3, double rainfall1, double rainfall2, double rainfall3);
void findLeastRainFall (string month1, string month2, string month3, double rainfall1, double rainfall2, double rainfall3);
void welcome();
double rainSum (double rainfall1 , double rainfall2, double rainfall3);

int main() {
//A. Declare and Initialize Variables to Store Rainfall for each county, month, least, greatest, and sum
string month1; //St lucie county
double rainfall1;//st lucie county
string county1 = "St. Lucie County";
string month2; //martin county
double rainfall2;//martin county
string county2 = "Martin County";
string month3; //palm beach county
double rainfall3;//martin county
string county3 = "Palm Beach County";

//B. Call welcome() to display the program description
welcome();

//C. Call getRainFall () for St Lucie County
getRainFall(county1, month1, rainfall1);

//D. Call getRainFall () for Martin County
getRainFall(county2, month2, rainfall2);
//E. Call getRainFall () for Palm Beach County
getRainFall(county3, month3, rainfall3);
//F. Call findGreatestRainFall ()

//G. Call findLeastRainFall ()

//H. Call rainSum () - Don't forget to capture the returned value

//I. Output the Sum in main

return 0;
}

/*FUNCTION DEFINITIONS*/
void getRainFall (string countyname , string &month, double &rainFall)
{
//Ask (cout) user for the month for "county name"
//read (cin) in user input a string month name
//ask user for rainfall for "county name"
//read in user input for rainfall
for (int i = 0; i < 45; i++); //validate user input - i.e value must be greater than 0 - loop
}
void findGreatestRainFall (string month1, string month2, string month3, double rainfall1, double rainfall2, double rainfall3)
{
//find out if the months are equal
//check if m1 is equivalent to m2 AND && m1 is equivalent to m3 -> true -> print only one month
//else if m1 is equivalent to m2 -> TRUE - print out two months
//else if....

//find the greatest value- to do this you must test each value against the other
}
void findLeastRainFall (string month1, string month2, string month3, double rainfall1, double rainfall2, double rainfall3)
{

}
void welcome()
{
cout << "*****************************************************************\n";
cout << "Welcome to the Rain Fall Program\n";
cout << "You will enter the rainfall for the surrounding 3 counties and the month\n";
cout << "it occurred (the Rain Fall Must be > 0).\n";
cout << "Program Developed by: Margaret Grosso\n";
cout << "***************************************************************** \n";
}
double rainSum (double rainfall1 , double rainfall2, double rainfall3)
{
double sum = 0;
//perform calculation, sum the 3 numbers
return sum;
}
Hello koaken,

Yes first idea:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.


Hang on for a bit while I put your code in my IDE so I can read it.

Andy
Hello koaken,

That is some improvement. At least it compiles with no errors.

The function prototypes match the function definitions. One thing I would suggest is in the function definitions use the same variable names as you defined in "main". Since these variable are local to the function and scope changes when you enter the function using the same names is not a conflict and when the function ends so do the local variables.

With a function using the same variable names as the function call it makes the function less confusing to work with.

In "main" instead of defining three sets of variables you may find it easier to put the county names and rainfall amounts in an array or vector. I suggest using a vector it is much easier to use.

For the "month" variable you only need one not three. Or you could be comparing snow fall to rainfall and without the proper calculation it does not match. Your program needs to deal with one month at a time.

The for loop in "getRainFall" is better used in "main" to replace the three function calls that you do have.

In the function "rainSum" if you pass a vector, (or array), of the rainfall all the function needs to do is return the sum of each element. There is no need for any extra calculation.

This is something I am thinking of. Look at it as a concept or a different approach of what could be done:
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
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

constexpr size_t CLEARSCREEN{ 2 };

void welcome();
void getRainFall(const std::string county, std::string monthName, std::vector<double>& rainfall);
void findGreatestRainFall(std::string monthname, std::vector<std::string> counties, std::vector<double> rainfall);


int main()
{
	const std::vector<std::string> counties{ "St. Lucie County", "Martin County", "Palm Beach County" };
	const std::string monthNames[]{ "", "January", "February", "March", "April", "may", "June", "July", "August", "September", "October", "November", "December" };

	size_t month{ 3 }; // <--- Set up this way for testing.
	std::vector<double> rainfall{ 3.256, 3.256, 2.256 }; // <--- Set up this way for testing.
	double sum{}, avg{};

	welcome();

	// <--- These next two parts are commented for testing.
	// ***************************************************************************

	//std::cout << "\n Please enter the month to record rainfall (January = 1): ";
	//std::cin >> month;

	//for (size_t lc = 0; lc < counties.size(); lc++)
	//	getRainFall(counties[lc], monthNames[month], rainfall);

	// ***************************************************************************

	findGreatestRainFall(monthNames[month], counties, rainfall);

	return 0;
}

void welcome()
{
	//for (int i = 0; i < 45; i++)
	//{
	//	std::cout << "*";
	//}

	const std::string line1{ "Welcome to the Rainfall Program" };
	const std::string line2{ "You will Enter the rainfall for the surrounding 3 counties and" };
	const std::string line3{ "the month it occurred (the Rain Fall Must be > 0)." };
	const std::string line4{ "Program Developed by: Koa" };

	std::cout << '\n' << ' ' << std::string(79, '*');
	std::cout << '\n' << std::setw((79 / 2) - (line1.size() / 2)) << ' ' << line1 << "\n";
	std::cout << std::setw((79 / 2) - (line2.size() / 2)) << ' ' << line2 << "\n";
	std::cout << std::setw((79 / 2) - (line3.size() / 2)) << ' ' << line3 << "\n";
	std::cout << "\n";
	std::cout << std::setw((79 / 2) - (line4.size() / 2)) << ' ' << line4 << "\n";
	std::cout << ' ' << std::string(79, '*') << "\n";
	std::cout << "\n Please enter a real number for the rainfall in inches (the number must be > 0). \n";

        for (size_t i = 0; i < CLEARSCREEN; i++)
		std::cout << "\n";
}

void getRainFall(const std::string county, std::string monthName, std::vector<double>& rainfall)
{
	double input{};

	std::cout << "\n Please enter " << county << "'s rainfall for the month of " << monthName << ": ";
	std::cin >> input;

	rainfall.emplace_back(input);
}

This is just the basic program. I have an example of using an array and a vector. If you are not up to vectors yet you can change it to an array and it will work the same. And the function "getRainfall" would need to be changed to use an array.

In the "getRainfall" function you could add a while loop to verify that your input is a number and that it is greater than zero. Since you are inputting a number you should check that a letter or something other than a number was entered. That is in addition to checking that the number input is greater than zero.

I will do a little more work and see what else I can come up with.

Hope that helps,

Andy
Topic archived. No new replies allowed.