Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gmcguinn

macrumors newbie
Original poster
Jan 20, 2011
28
0
Dublin, Ireland
Code:
[COLOR="DarkOrange"]#include[/COLOR] <iostream>
[COLOR="DarkOrange"]#include[/COLOR] <string>

[COLOR="DarkOrange"]using namespace[/COLOR] std;

[COLOR="DarkOrange"]int[/COLOR] main ()
{										
	[COLOR="DarkOrange"]int[/COLOR] count, SENTINEL;											
	[COLOR="DarkOrange"]double[/COLOR] sum, min, max, average, temp;
	[COLOR="DarkOrange"]string[/COLOR] station;
	
	count=0;
	sum=0;
	SENTINEL=-999;
																	

		cin >> station;
		cin >> temp;												 
		
		max=temp;
		min=temp;
	
	[COLOR="DarkOrange"]while[/COLOR] (temp != -999)
	{															
		count=count+1;												
		sum=sum+temp;
		
		[COLOR="DarkOrange"]if[/COLOR] (temp>max)									
		{
			max=temp;									          	 
		}
		
		[COLOR="DarkOrange"]if[/COLOR] (temp<min)									
		{
			min=temp;												
		}
		
		cin >> temp;												
	}
	
	
	average=sum/count;
	
	cout << station << endl;
	cout << [COLOR="red"]"Average is : "[/COLOR] << average << endl;
	cout << [COLOR="red"]"Sum is : "[/COLOR]	<< sum << endl;
	cout << [COLOR="red"]"Max is : "[/COLOR] << max << endl;
	cout << [COLOR="red"]"Min is : "[/COLOR] << min << endl;
	
	
	[COLOR="DarkOrange"]return[/COLOR] 0;
}
 
Last edited:
That works fine but how to I adjust the program so that it can take an input such as :

"DUBLINAIRPORT 10.6 13.3 14.2 -999"

Strip off the location name outside the loop before your first "cin >> temp;" Have you learned about strings or arrays of char yet? (EDIT: clearly since you include <string>)

NOTE: You don't seem to be doing the min/max stuff yet.

Check out this thread for something similar in C https://forums.macrumors.com/threads/1092350/

B
 
Strip off the location name outside the loop before your first "cin >> temp;" Have you learned about strings or arrays of char yet? (EDIT: clearly since you include <string>)

NOTE: You don't seem to be doing the min/max stuff yet.

Check out this thread for something similar in C https://forums.macrumors.com/threads/1092350/

B

Yea thanks.
After an hour or so I figured it out.
Thanks again!
 
For future reference, don't remove the content of your original post if you solved the problem. Just add the thread prefix and leave it alone. This helps future readers understand the complete issue if they had the same problem as well.
 
For future reference, don't remove the content of your original post if you solved the problem.

I hadn't noticed that! What I meant was add a new post to the end of the thread with the fixed code and change the thread prefix. As kainjow says this gives other readers a chance to see where you were stuck and how you got around it.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.