I have run into a unsolvable runtime error, I always get the message invalid floating point error, with the following C++ program. This program reads floats from a file(float.txt)
1.56
.98
5.78
Then sorts to put the largest float on top. But when I try to read this I get the ERROR Invalid floating point error. I am not a student in fact I am in scrap metal currently recovering from a broken wrist. needed is the above file float.txt program below.
I have struggled with this for a week, float.txt attached.
#include <ctype.h>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <iostream.h>
#include <math.h>
#include <ostream.h>
#include <stdlib.h>
#include <stdio.h>
ifstream infile1,infile2,infile6,infile7;
int Gnum,amountRead = 0,max_read = 99,i = 0,sn,ii;
const int maxn = 4200;
float array[maxn] = {0.00000};
float num,x = 0,xx;
void getfloat(),read();
float sort();
float sort()
{
int j;
float temp;
for(i=0;i<amountRead;i++);
for(i=0;i<amountRead;i++)
for(j=0;j<amountRead-i;j++)
if(array[j]<array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
amountRead++;
for(ii = 0;ii<amountRead;ii++)
{
if(array[ii] != 0)
{
cout<<array[ii]<<endl;
xx = array[ii];
ofstream output14("sort2.txt",ios::app);
output14<<xx<<endl;
output14.close();
}
}
}
void getfloat()
{
infile7.open("sort2.txt");
infile7>>x;/// ERROR HERE
while(infile7)
{
infile7>>x;/// ERROR HERE ALSO
ofstream output15("sort3.txt",ios::app);
output15<<x<<endl;
output15.close();
}
infile7.close();
}
void main()
{
infile6.open("float.txt");
while(infile6>>array[amountRead]&& amountRead < max_read)
{
amountRead++;
}
for(i = 0; i < amountRead; i++)
{
cout<<array[i]<<endl;
}
infile6.close();
sort();
getfloat();
getch();
} ///End of main