Homework #3


Copy the table into a Word processor (such as Word) and fill in the answers.
Submit the .pdf file on eCampus.


Do these conditions evaluate to true or false?   (4 points each)

short int A = 5, B = -8, C = 18, D = 0;

1. ________  (A > B) 7. ________  (D >= C || A == B)
2. ________  (B <= 0) 8. ________  ((C + 1) == (D + 19))
3. ________  (D != 0) 9. ________  (B == 0 || C == 0 || D == 0)
4. ________  (C = 17) 10. ________  (A == 0 && (B > 1 || C > 1))
5. ________  (A > B && C > D) 11. ________  (!(A = 5) || !(C = 8))
6. ________  (C != (B + 28)) 12. ________  (A > (B + C) && A < (D + B))

13. Write a condition for the if statement that makes the code correct. (10 points)

   int X, Y;
   cout << "Enter a value for X: ";
   cin >> X;
   cout << "Enter a value for Y: ";
   cin >> Y;
   if (write condition)
      cout << "Both X and Y are even";

14. Write a condition for the if statement that makes the code correct. (10 points)

   int X, Y, Z;
   cout << "Enter a value for X: ";
   cin >> X;
   cout << "Enter a value for Y: ";
   cin >> Y;
   cout << "Enter a value for Z: ";
   cin >> Z;
   if (write condition)
      cout << "Exactly two of the variables are negative";


15. (30 points) Copy the source code for the program below into your Word document using a syntax highlighter (such as tohtml.com) so it is presentable.

Write a program that prompts the user to enter how many donuts they are going to buy.  The program should then output how many dozen and single donuts this is.  For example, if the user enters 29, the program will say, "This is 2 dozen plus 5 single donuts."

Also, have the program output different comments (minimun 6) depending on how many donuts the user enters.  The ranges for the comments should be contiguous.  Look at the example below, but use your own original comments and ranges.

If the user eats this many donuts The program will output this
0 "On a diet or something?"
1 - 2 "You don't seem very hungry today"
3 - 6 "Just an appetizer for you?"
7 - 9 "What's for dessert...cinnamon rolls?"
10 - 12 "You're a donut freak!"
> 12 "Mmmmmmm......donuts!"