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];
}