Illegal use of floating point error

Hi,below is a source code when i compile it compler gives the error "illegal use of floating point" does any one could tell me that where is error.and how to resolve this.

#include<iostream.h>
#include<conio.h>
int main()
{
double gallons,miles,totalgallons=0.0,totalmiles=0.0,average;
cout<<"enter the gallons used(-1 to end):";
cin>>gallons;
while(gallons |= -1.0 )
{
totalgallons+=gallons;
cout<<"enter the miles driven";
cin>>miles;
totalmiles+=miles;
cout<<"miles/gallon for this tank was"<<miles<<"\n\enter the gallons used(-1 to end);";
cin>>gallons;
}
average=totalmiles/totalgallons;
cout<<"\nthe overall average miles/gallon was"
<<average<<endl;
getch();
return 0;
}
Last edited on
while(gallons |= -1.0 )
That's a bitwise OR assignment operator. You need the "not-equal" operator:
while(gallons != -1.0)
Due to precision nonsense, I'd probably just use this instead:
while (gallons >= 0)
Topic archived. No new replies allowed.