Homework 3 Due Monday, September 30, 2002 Solutions a. int true; "true" is a keyword, so you can't use it as a variable name. b. const int conversion_factor(1.61); conversion_factor should be stored as a float rather than an int c. int acct_balance = 32,167; commas cannot be used in variable initializations/values d. cout << "Thank you for using this program!\endl"; It looks like they're mixing up endl with \n. It should be either cout << "Thank you for using this program!" << endl; or cout << "Thank you for using this program!\n"; e. num1*num2=ratio; ratio should be on the left hand side with num1*num2 on the right hand side (the left-hand-size should refer to a variable) f. double hour; In this example, the hour must be stored as an int, because we are using it with the % operator g. cout << "Please enter your name" needs a semicolon The semicolon at the end of the line is missing h. if (age < 18); There shouldn't be a semi-colon at the end of the line 7) c is (3%4)*6, or 18 d is then 18/4 or 4 (integer division - the remainder is truncated) lastly, e is (3+4+18+4)/4 or 29/4, or 7 (again, the remainder is truncated) 13) x = 20 (17 + 15/4 or 17 + 3 or 20) y = 15 (its value never was changed) z = 6 (20%3+4 = 2+4 = 6) w = 11.5 (17/3 + 6.5, or 5+6.5 or 11.5, no truncation since w is a double) t = 4.5 (20/4.0 + 15%4 - 3.5 = 5 + 3 - 3.5 = 4.5) 15c) 37.6 (13/5.0 + 2*17.5) 15e) 10 (17%5+13-5 = 2+13-5) 18b) const char Blank = ' '; const int one = 5; int main() { int a, b, cc; a = one + 5; b = a + Blank; cc = a + one * 2; b = a + cc; cout << "a = " << a << ", b = " << b << ", cc = " << cc << endl; return 0; } 19a) x *= 2; 19b) x += y - 2; 19c) sum += num; 19d) z *= (x+2); 19e) y /= (x+5); 21) a b c 9 7 UND 9 8 26 10 45 27 22) a b c sum 3 5 14.1 22 3 5 4.7 22 3 6 4.7 22 50 6 4.7 22 2a) (i) Hello There 2c) (ii) 3 5) if(score >= 60) cout << "You pass." << endl; else cout << "You fail." << endl;