Expand|Select|Wrap|Line Numbers
- int main()
- {
- ifstream infile;
- ofstream outfile;
- float num1,num2,num3,limit1=0,limit2=0,counter1=0,counter2=0,sum=0;
- float aver;
- infile.open("testin.txt");
- outfile.open("testout.txt");
- if (infile.fail() || outfile.fail())
- {
- cout<<"failed";
- return 1;
- }
- else
- while(!infile.eof())
- {
- infile>>num1>>num2;
- limit1=num1;
- limit2=num2;
- while(counter1<limit1)
- {
- sum=0;
- counter2=0;
- while (counter2<limit2)
- {
- infile>>num3;
- outfile<<num3<<" ";
- sum+=num3;
- counter2++;
- }
- outfile<<"\nTotal ="<<sum<<endl;
- aver=sum/limit2;
- outfile<<"Average ="<<aver<<endl;
- outfile<<"____________________"<<endl;
- counter1++;
- }
- }
- return 0;
- }
when i try to read num 3 inside the
and then initialing
minValue and maxValue to it
and the read the num3 again inside the while(counter1<limit1)
like
while(counter1<limit1)
{
sum=0;
counter2=0;
infile>>num3;
and then read the same number inside the
while (counter2<limit2)
and compare them using
Expand|Select|Wrap|Line Numbers
- if(maxValue<num3)
- maxValue=num3;
- else if(num3<minValue)
- minValue=num3
- else
- {
- minValue=num3
- maxValue=num3
- }
any suggestions?