• Welcome to the new NAXJA Forum! If your password does not work, please use "Forgot your password?" link on the log-in page. Please feel free to reach out to [email protected] if we can provide any assistance.

C++ help

XJMK

aka boredchimp
Location
Neenah, WI
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
 
boredchimp said:
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.
 
thanks for the reply

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

got it all straightend out now.
 
Back
Top