1. Create a new project. Type in the following program. Add a
comment at the top to include your name and the date.
2. Compile and Run with different values. What data values
should you choose? Think about what we discussed in class.
3. Add code to compute the modulus. Hint: you will also have
to declare a new variable.
//this program demonstrates the use of various operators
#include <iostream >
using namespace std;
int main()
{
int num1;
int num2;
int sum;
int diff;
int prod;
float quot;
cout << "Enter two integer values" << endl;
cin >> num1 >> num2;
sum = num1 + num2;
cout << num1 << " + " << num2 << " is
" << sum << endl;
diff = num1 - num2;
cout << num1 << " - " << num2 << " is
" << diff << endl;
prod = num1 * num2;
cout << num1 << " * " << num2 << " is
" << prod << endl;
quot = (float) num1 / num2;
cout << num1 << " / " << num2 << " is
" << quot << endl;
return 0;
}
4. Answer the following questions:
• What data values should you choose to test the program?
Think about what we discussed in class.
• What happens when num2 is 0? Why?
• What does this tell you about using division or modulus in
your programs?
5. Add the following lines to correct the divide by zero
problem. Compile and run with different values to ensure it works
correctly.
if (num2 == 0)
{
cout << “cannot divide by zero!” << endl;
}
else
{
…
}
6. Submit program, output and questions as one .doc file on
Blackboard.