Embercode
✕
C++ LoopsQuick quiz

Digits and menus

7 questions. Covers Input-driven menus.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``cpp #include <iostream> using namespace std; int main() { int n = 9080; int reversed = 0; while (n > 0) { reversed = reversed * 10 + n % 10; n /= 10; } cout << reversed << '\n'; } ``
  2. 2. What does this program print? ``cpp #include <iostream> #include <sstream> #include <string> using namespace std; int main() { istringstream in("hello\nwave\nquit\nbye\n"); string word; while (getline(in, word)) { if (word == "quit") { cout << "Goodbye.\n"; break; } cout << "word: " << word.size() << '\n'; } cout << "done\n"; } ``
  3. 3. Inside a digit loop, n /= 10; removes the last digit. Write the same step without the shorthand: n = n ___ 10;

    Type your answer.

  4. 4. When stoi gets text with no number at all, such as "abc", it throws an exception of type ___.

    Type your answer.

  5. 5. What does sum_digits(-4721) return in the lesson's digit-sum function, and why?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.