Homework 3 Solution
1. Identify which of the following are legal variable names. For those that are not legal, indicate why.
2. Copy and paste the following program into the Microsoft Visual C++ and compile. Examine the errors generated by the compiler. For EACH error reported by the compiler, circle the line causing the error, and indicate what would need to be changed on the line in order to remove the error.
// Convert nickels and dimes to cents.
using namespace std;
int nickels, dimes, cents;
nickels = 3;
Dimes = 7; // Dimes should be dimes since ‘int dimes’ is declared above
cents = 5 * nickels + 10 * dimes;
cout << nickels << " nickels and ";
cout << dimes << " dimes " << endl;
cout << "= " << cents << " cents " // missing semi-colon at the end of the line
3. Using Microsoft Visual C++, fix each compiler error in question 2 above.
Turn in: Printout this homework assignment and annotate with your answers to questions 1 and 2. For question 3, attach a printout of the source code for your program, and a screen capture of the window showing your program successfully compiling. Note: to capture a screen image, click in the window you want to capture, press <Ctrl><Alt> <Printscreen>, and paste the picture into, for example, a Word document. Consider using RAPTOR to plan out the algorithm of your program before you start with the actual code! Don't forget to turn in the answers to question 1.