Turbo C++ Debugging Lab

Tom Kelliher, CS17

Feb. 23, 1996

Some diskettes will be provided which contain the following program. The program name is broken.cpp. Load the program, then do a ``Save as'' to save it onto you N: drive. Then, pass the diskette along to the next person.

Using this program:

  1. Remove any syntax and/or other errors which prevent the program from compiling
  2. Run the program with several different inputs. Do there appear to be any run-time or design errors? (There should be a few.)
  3. Use the debugger to single step the program, set and use breakpoints, set some watches, and modify some variables
  4. Fix the program so that it runs correctly

void main()
{
   int change;
   int quarters;
   int dimes;
   int nickels;
   int pennies

   cout << "Enter amount of change to be returned: ";
   cin >> Change;

   quarters = 0;
   while (change >= 25)
   {
      quarters = quarters + 1;
      change = change - 25;
   }

   dimes = 0;
   while (change >= 10)
   {
      dimes = dimes + 1;
      change = change - 25;
   }

   nickels = 0;
   while (change >= 5)
   {
      nickels = pennies + 1;
      change = change - 5;
   }

   pennies = change;

   cou << "Quarters: " << quarters << endl;
   cout << "Dimes: " << dimes << endl;
   cout << "Nickels: " << nickels << endl;
   cout << "Pennies: " << pennies << endl;

   return 0;
}



Thomas P. Kelliher
Thu Feb 22 15:43:18 EST 1996
Tom Kelliher