CS 1440 pre-lab activities for Lab 4

Before coming to the lab you should answer the following questions in writing.
1. The following C++ program computes the value of 34.  Modify the program to do the computation for 24, 33, 54, and 45 and to display the results.
// This C++ program computes the value of 34.
#include<iostream>
int main(void)
{
int i = 0, p = 1;
int x = 3, y = 4;
while(i < 4)
{
p = p * x;
i++;
}
cout << x << " to the power of " << y << " is = " << p << endl;

return 0;
}

Note: Do not write 4 programs, modify the same program to compute all of them.

2. Suppose you have a C++ program, like the one that does your taxes, and you want to display the results both rounded up and down.  How would you round a real value up?  How would round a value down.

Hint:  To round a number down, drop the decimal point.  For example:  23.56 will become 23 when you round it down.  To round a number up, first add 1 to it, then drop the decimal point. In the above example: 23.56 + 1 = 24.56, so the round up of 23.56 will become 24.

3. What does the following C++ program display?
#include<iostream>
int main(void)
{
int x,y;
cout << "Enter 2 values for x and y separated by space, then press <Enter> :";
cin >> x >> y;
cout << endl;

cout << x << "/" << y << " = " << x/y << endl;

return 0;
}

Does your program produce the correct answer for x = 2 and y = 4?  If not, explain why it does not produce the correct answer and how will you go to fix the problem.

As we mentioned in lab3, looping helped us to simplify our computation significantly.  In lab4, we will use functions to simplify our computations even more.