Weather Code help

Could someone help me solve this. Not sure why it wont keeps freaking out on me. I think my compiler is broken or I am totally missing something

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
  #include <iostream> 
using namespace std; 
int main() 
{ 
	const int NUM_MONTHS = 12; //number of values 
	int values[NUM_MONTHS]; //each value 
	int month; //loop counter 
	int lowest, highest, rainfall, count; 
	double average; 
	double total = 0; 

	//Array with the names of the months 
	string months[NUM_MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 

	//Input rainfall for each month 
	for(int month = 1; month <= NUM_MONTHS; month++) 
	{ 
		cout << "Enter the total rainfall for " << months[month-1] << ": "; 
		cin >> rainfall; 
		//Input validation - enter a value over or equal to 0 
		if ( rainfall < 0 ) 
		{ 
			cout << "The number you have entered is invalid." << endl; 
			cout << "Please reenter: "; 
			cin >> rainfall; 
		} 

		//Calculate total rainfall for the year 
		total += rainfall; 
	} 

	//Calculate the average monthly rainfall 
	average = total/12; 

	//Find the months with the highest rainfall and lowest rainfall 
	highest = values[0]; 
	lowest = values[0]; 

	for(int month = 0; month < NUM_MONTHS; month++) 
	{ 
		if(values[month] > highest) 
		highest = values[month]; 
		if(values[month] < lowest) 
		lowest = values[month]; 
	} 

	//Display total rainfall for year, monthly average, highest and lowest months 
	cout << "\n\nThe total rainfall for the year is: " << total << " inches" 
	<< "\nThe average monthly rainfall is: " << average << " inches"; 
	cout << "\nThe month with the highest rainfall is: " << highest 
	<< "\nThe month with the lowest rainfall is: " << lowest << endl; 

	system("pause"); 
	return 0; 
}
#include <string> ?

Not sure what you meant by freakout. Is the compiler complaining or are you having a runtime problem? The code above with #include <string> included compiled for me. If it is a runtime issue, tell us what your inputs and results were.
Last edited on
The compiler keeps giving me LNK2005 and LNK1169 errors. I have yet to get a program to run properly on this machine for some reason. Its a 64bit and ive had to uninstall and reinstall and install other Visual Studio Basic versions.


Edit: Im dumb. Was doing multiple programs all under one project.
Last edited on
Hmm... did you drop this file into a Visual Studio project that has other program files in it? Do you have other files in your project that have int main() in them?

EDIT: Ha, looks like I was a couple minutes late.
Last edited on
Topic archived. No new replies allowed.