Yes. This might happen if premium gas gives a lower MPG in your car. Or, more likely, if the second tank was used up in a different type of driving than the first.
Here is a sample run of the program.
Enter the first odometer reading ? 25000 Enter the second odometer reading ? 25300 Enter the first gallons ? 10 Enter the third odometer reading ? 25650 Enter the second gallons ? 11 Your mileage improved by 1.8182 miles per gallon
The above program solves the problem, but it might be nicer if the output were more user friendly. As it is, if the mpg rate goes down with premium gas, the program will print something like:
Your mileage improved by -2.7121 miles per gallon
It would be nice if the program printed a different message when the rate did not improve. This calls for the two-way decision type of control structure. The QBasic statements for the last task, write out the result could be:
IF IMPROVEMENT >= 0.0 THEN PRINT "Your mileage improved by", IMPROVEMENT, " miles per gallon" ELSE PRINT "Your mileage decreased by", -IMPROVEMENT, " miles per gallon" END IF
Notice what we did: the general description of the final task, write out the result was not changed, but we solved it in a different way than before.
Did the over-all control structure of the program change when we changed the statements for the last task?