PDA

View Full Version : C++ help


XJMK
October 5th, 2006, 18:05
I've got this dumb program with functions and I don't understand whats wrong. Heres one of them, the rest are basically the same, just different variables.

double getGallons();
{
double gallons;

cout << "\nEnter the number of gallons of fuel (between 0.0 and 40.0): ";

cin >> gallons;

while (gallons <0.0 || gallons > 40.0)
{
cout <<"Gallons entered must be between 0.0 and 40.0 \n Try again: ";
cin >> gallons;
}

return gallons;
}

The error says warning: return to 'int' from 'double'

What does that mean? I wrote it the way the teacher described, but she uses pseudo-code sometimes so I don't always understand. TIA

HilltopXJ
October 5th, 2006, 19:31
I've got this dumb program with functions and I don't understand whats wrong. Heres one of them, the rest are basically the same, just different variables.

double getGallons();
{
double gallons;

cout << "\nEnter the number of gallons of fuel (between 0.0 and 40.0): ";

cin >> gallons;

while (gallons <0.0 || gallons > 40.0)
{
cout <<"Gallons entered must be between 0.0 and 40.0 \n Try again: ";
cin >> gallons;
}

return gallons;
}

The error says warning: return to 'int' from 'double'

What does that mean? I wrote it the way the teacher described, but she uses pseudo-code sometimes so I don't always understand. TIA


I haven't tried to compile the function yet, but i'd guess that your passing getGallons() to a int somewhere in your main() program.

Example:
Main(){
//.....
int fubar

fubar = getGallons();

//.......
}

Thats what i guess return to 'int' from 'double' means.

XJMK
October 6th, 2006, 12:19
thanks for the reply

I guess the functions go after the int main's return.

got it all straightend out now.