Exercises
-
4.11 (Correct the Code Errors) Identify and correct the error(s) in each of the following:
if (age >= 65); { cout << "Age is greater than or equal to 65" << endl; } else { cout << "Age is less than 65 << endl"; }
if (age >= 65) { cout << "Age is greater than or equal to 65" << endl; else; { cout << "Age is less than 65 << endl"; }
unsigned int x{1}; unsigned int total; while (x <= 10) { total += x; ++x; }
While (x <= 100) total += x; ++x;
-
while (y > 0) { cout << y << endl; ++y; }
-
4.12 (What Does this Program Do?) What does the following program print?
1 // Exercise 4.12: Mystery.cpp 2 #include <iostream> 3 using namespace std; 4 5 int main() { 6 unsigned int x{1}; 7 unsigned int total{0}; 8 9 while (x <= ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.