Fuel Program Activity

 

You’ve already entered the FUEL program and saved the project and source code to your drive.  Hopefully, it has it’s own folder and a stand-alone exe file has been created.  Next, open your code and make some adjustments.  As you make these changes, please answer the related questions on a piece of notepaper.

 

Your program, as it is in the book, won’t hang out on your screen for long enough to see the results.  Add a getch() line at the bottom of the main function. 

 

  1. Without adding another include statement, the getch() statement will cause an error.  Write the error you get by trying to use the getch() line without including conio.h.

 

 

In order for getch() to function, you must include the conio header file.  Add the second include for conio.h.  Now, your program should compile, show results of your calculations, and wait for you to enter a character before moving on.

 

  1. Enter the following test data (miles traveled = 100, gallons used = 5, price/gallon = 2.25.).  Write the results here:

 

 

  1. It’s important that your cout and cin operators flow in the correct direction (>> vs <<).  Reverse the direction of your cout operator somewhere and write down the error you get.  Is it the same error you get if you reverse a cin operator?

 

 

  1. This program declares five variables, all of which are declared as FLOAT.  (This is a data type, like string or numeric in Qbasic.)  We’ll be dealing with data types in chapter three, but data types can certainly affect your results when calculating.  Change your declarations (all five) to INT instead of FLOAT.  Run your program with the same test data as #2 above and record your results.

 

  1. How do you think that the results from above were arrived at?

 

  1. Look for two lines that most closely resemble a LET statement in Qbasic.  Write them here.

 

  1. Based on this program, write the QBASIC statement that most closely matches the following C++ keywords:

 

    1. FLOAT
    2. //
    3. CIN
    4. COUT