Hi, I am a c++ beginner. I have written this code below. The compiler recognizes it and compiled it. But once the program gets into the loop, I can't get out of the loop even by meeting the conditions. I checked the syntax of the code and I don't think there is anything wrong with it. But I don't know what's wrong with it. Please help. I gratefully appreciate it. Thank you!
Code://************************************************************* // Mileage Program // This program computes the miles per gallon a car gets on a // trip //************************************************************* #include <iostream> #include <string> using namespace std; int main() { int fillupFlag; // Flag variable to exit the fillup loop float startingMileage; // Starting mileage float endingMileage; // Ending mileage float fillup; // amount(s) in gallons of fillups float milesPerGallon; // miles per gallon the car gets on the trip float totalFillup; // sum of the amount of fillups totalFillup = 0; // Total amount of fillup in the beginning fillupFlag = 1; // Initializing the flag variable // not equal to 0 so that the program does not skip the loop cout << "Welcome to the Mileage Program!" << endl; cout << "This program computes the miles per gallon a car gets " << "on a trip" << endl; cout << " " << endl; cout << "Please enter the starting mileage: " ; cin >> startingMileage; cout << "Please enter the ending mileage: " ; cin >> endingMileage; while (fillupFlag != 0) { cout << "Fillup #" << fillupFlag << endl; cout << "Please enter the amount of the fillup in gallons" << endl; cout << "(Enter 0 when there is no more fillup): "; cin >> fillup; totalFillup = totalFillup + fillup; // Calculating total // amount in gallons of fillups if (fillup = 0.0) // Are there anymore fillups? fillupFlag = 0; // No. else fillupFlag++; // Yes. } milesPerGallon = (endingMileage - startingMileage) / totalFillup; cout << "The miles per gallon your car gets on the trip is" <<" approximately " << milesPerGallon << " miles per gallon." << endl; // Outputing the results return 0; }