// ============================================ // Control Statements (p. 14) #include #include using namespace std; int main() { cout << INT_MIN << " " << INT_MAX << "\n"; return 0; } // ============================================ // Control Statements (p. 15) cout << "int " << sizeof(int) << "\n"; cout << "char " << sizeof(char) << "\n"; cout << "bool " << sizeof(bool) << "\n"; short s = 0; cout << "short int " << sizeof(s) << "\n"; long l = 0; cout << "long int " << sizeof(l) << "\n"; cout << "unsigned short int " << sizeof(unsigned short) << "\n"; cout << "unsigned int " << sizeof(unsigned) << "\n"; cout << "unsigned long int " << sizeof(unsigned long) << "\n"; // ============================================ // Control Statements (p. 16) int i = 0; short sGood = 32765; while (i < 10) { short sBad = sGood + i; cout << sGood + i << " " << sBad << "\n"; i = i + 1; } // ============================================ // Control Statements (p. 21) bool b = 0; cout << b << "\n"; b = 1; cout << b << "\n"; b = 10; cout << b << "\n"; b = 0.1; cout << b << "\n"; b = -1; cout << b << "\n"; // ============================================ // Control Statements (p. 24) double income = 0, tax = 0; cout << "Please enter the taxable income: "; cin >> income; if (income <= 10000) tax = 0.02 * income; else tax = 0.08 * (income - 10000) + 10000 * 0.02; cout << "Tax amount: $" << tax << "\n"; // ============================================ // Control Statements (p. 32) #include using namespace std; int main() { int num1 = 0, num2 = 0; cout << "Please enter one number: "; cin >> num1; cout << "Please enter another number: "; cin >> num2; cout << "The sum is " << num1 + num2; return 0; } // ============================================ // Control Statements (p. 36) int a = 0, b = 0; if ((a > 10) && (b = 1)) ; cout << b << "\n"; if ((a < 10) || (b = 1)) ; cout << b << "\n"; // ============================================ // Control Statements (p. 43) int sum = 0; int i = 1; while (i <= 100) { sum = sum + i; i = i + 1; } cout << sum << "\n"; // ============================================ // Control Statements (p. 43) char a = 0; // do something cout << "Exit? "; cin >> a; while (a != 'y' && a != 'Y') { // do something cout << "Exit? "; cin >> a; } // ============================================ // Control Statements (p. 53) int sum = 0; for (int i = 1; i <= 100; i++) sum = sum + i; cout << sum; // ============================================ // Control Statements (p. 54) for(int i = 0, j = 0; i < 10, j > -5; i++, j--) cout << i << " " << j << "\n"; // ============================================ // Control Statements (p. 59) for (int x = 1; x <= 3; x++) { for (int y = 1; y <= 3; y++) cout << "(" << x << ", " << y << ") "; cout << " "; } // where to output a new line character? // ============================================ // Control Statements (p. 61) for (int a = 1; a <= 100; a++) { if(a % 10 != 0) cout << a << " "; } // ============================================ // Control Statements (p. 61) for (int a = 1; a <= 100; a++) { if (a % 10 == 0) continue; cout << a << " "; } // ============================================ // Control Statements (p. 62) int a = 0, b = 0; while(a <= 10) { while(b <= 10) { if(b == 5) break; cout << a * b << "\n"; b++; } a++; } cout << a << "\n"; // ? // ============================================ // Control Statements (p. 63) char a = 0; cout << "Exit? "; cin >> a; while (true) { cout << "Exit? "; cin >> a; if (a == 'y' || a == 'Y') break; }