Physics 5—Midterm Exam—Spring ’04 Name________________________________
Enter a guess for the number between 1 and 100
62
Your guess is too low.
Enter a guess for the number between 62 and 100
86
Your guess is too low.
Enter a guess for the number between 86 and 100
95
Your guess is too low.
Enter a guess for the number between 95 and 100
98
Your guess is too low.
Enter a guess for the number between 98 and 100
99
Congratulations! The target was, in fact, 99.
a.
#include <iostream>
int main()
{
int x = 10;
while(x != 1) x /= 5;
cout << x;
return 0;
}
b.
The following
code is meant to assure that the input is in the range between 1 and 100. How does it do?
#include
<iostream.h>
void main()
cout << “\nEnter a number
between 1 and 100:” endl
do
cin >> guess;
while(guess>0
&& guess<UpperBound)
cout << “Your guess was “
<< setw(5) guess;
return 0;