954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

: warning C4552: '>' : operator has no effect; expected operator with side-effect

so I've been trying to write this program that takes the data from a file and outputs the year the rainfall how much it is below/above the average, the average raifall and the std deviation and for some reason I get three C4552 warnings:'>': operator has no effect on three for loops. Help is highly appreciated :(

#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cstring>
#include<cstdlib>

using namespace std;

void readFile(int month[],int year[],double rain[],const int size);

double averageRainfall(double rain[],const int size);
double belowRainfall(double size,double rain[],double Below[]);
double standardDeviation(double Below[],double size);
string monthName(int month[], const int size,string monthN[]);



int main()

{

const int size=12;
int year[size]={0};
int month[size]={0};
double rain[size]={0};
double Below[size]={0};
string monthN[size]={0};






int i;
i=0;

readFile(month,year,rain,size);
belowRainfall(size,rain,Below);
monthName(month,size,monthN);



cout<<"MONTH"<<"\t"<<"YEAR"<<"\t"<<"RAINFALL"<<"\t"<<"BELOW"<<endl;

for(i>0;i<size;i++)
cout<<monthN[i]<<"   \t"<<year[i]<<"\t"<<rain[i]<<"\t"<<"\t"<<setprecision(2)<<Below[i]<<endl;




cout<<"\n"<<"Average rainfall is  "<<setprecision(2)<<averageRainfall(rain,size)<<endl;


cout<<"\n"<<"Standard deviation is "<<setprecision(2)<<standardDeviation(Below,size)<<"\n"<<endl;

return 0;
}
 
 
void readFile(int month[],int year[],double rain[],const int size)
{
  
  int i;
ifstream inFile;
 inFile.open("rainfall.txt");
 if(!inFile)
 {
  cout<<"File could not open!"<<endl;
 exit(1);
 }

 for(i=0;i<size;i++)
  inFile>>month[i]>>year[i]>>setprecision(2)>>rain[i];
 inFile.close();
}


double averageRainfall(double rain[],const int size)
{
	int i;
	double sum;
	double average;
	sum=0;
	average=0;

	for (i=0;i<size;i++)
		sum=sum+rain[i];
		average=sum/size;

		return average;
}

double belowRainfall(double size,double rain[],double Below[])
{
	int i;
	double sum;
	double average;
	sum=0;
	average=0;

	for (i=0;i<size;i++)
		sum=sum+rain[i];
		average=sum/size;

		for (i=0;i<size;i++)
			Below[i]=rain[i]-average;

		return Below[i];
}
			
double standardDeviation(double Below[],double size)
{
	double sum;
	sum=0;
	int i;
	i=0;
	
	double deviation;

	for (i>0;i<size;i++)
		sum=sum+pow(Below[i],2);
		
	

	deviation=sqrt(sum/size);

	return deviation;
}

string monthName(int month[], const int size,string monthN[])
{
	int i;
	i=0;

	for(i>0;i<size;i++)

			switch(month[i])
	{
		case 1:
			monthN[i]="January";
			break;
		case 2:
			monthN[i]="February";
			break;
		case 3:
			monthN[i]="March";
			break;
		case 4:
			monthN[i]="April";
			break;
		case 5:
			monthN[i]="May";
			break;
		case 6:
			monthN[i]="June";
			break;
		case 7: 
			monthN[i]="July";
				break;
		case 8:
			monthN[i]="August";
				break;
		case 9:
			monthN[i]="September";
			break;
		case 10:
			monthN[i]="October";
			break;
		case 11:
			monthN[i]="November";
			break;
		case 12:
			monthN[i]="December";
			break;
	}
	
	return monthN[i];
}
biogig
Newbie Poster
3 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 
46. for(i>0;i<size;i++)


The first statement in a for loop's header must be an assignment statement, not a relational statement.

Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
 
for(i>0;i<size;i++)


i > 0 , first condition is initialization, since you do comparison it evaluates condition to false and sets i = 0; since 0 is not greater then 0. I assume you meant to do i = 0;

Crutoy
Junior Poster in Training
64 posts since Jan 2011
Reputation Points: 10
Solved Threads: 6
 

omg of course, thank you so much I don't know what I was thinking lol :)

biogig
Newbie Poster
3 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: