I am trying to get the user to keep inputing something until they enter a sentinel value here is an example of what I want to do:
Code:
#include <iostream>

using namespace std;

int main()
{
    int MilesDriven;
    float GallonsUsed;
    int TotalGallons;
    
    int TotalMiles;
    
    float MPG;
    int TotalMPG;
    
    while (GallonsUsed != -1)
    {
          TotalGallons = GallonsUsed + GallonsUsed;
          TotalMiles = MilesDriven + MilesDriven;
          TotalMPG = MPG + MPG;
          
          cout <<"How many gallons used : ";
          cin >>GallonsUsed;
          
          cout <<"How many miles driven : ";
          cin >>MilesDriven;
          
          MPG = MilesDriven / GallonsUsed;
          
          cout <<"The miles/gallon for this tank was " <<MPG;
          cout <<endl;
    }
      cout <<"The average miles/gallon was " <<TotalMPG <<endl;
      system("PAUSE");     
      return 0;
}
It works fine but if the user inputs -1 it continues with the rest of the loop before exiting. I need it to leave the while loop when the user enters -1 for GallonsUsed.