Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 558 Bytes

5.18.md

File metadata and controls

27 lines (21 loc) · 558 Bytes

(a)

//do  // Need a block here.
do {
  int v1, v2;
  cout << "Please enter two numbers to sum:" ;
  if (cin >> v1 >> v2)
  cout << "Sum is: " << v1 + v2 << endl;
//while (cin);
} while (cin);

(b)

int ival;
do {
  // ...
//} while (int ival = get_response());  // Error: declaration in a do condition
} while (ival = get_response());

(c)

int ival;
do {
  //int ival = get_response();  // Loop will define a new condition variable everytime
  ival = get_response();
} while (ival);