Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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:
1) What data values should you choose to test the program? Think about what we discussed in class.
2) What happens when num2 is 0? Why?
3) 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

{

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago