Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C ++ please Lab 1 Enter and run the following program: int num1; int num2 = 5; cout < < Please enter an integer: ;

C ++ please
Lab 1
Enter and run the following program:
int num1;
int num2 = 5;
cout << "Please enter an integer: ";
cin >> num1;
cout << "num1 = " << num1 << " and num2 = " << num2 << endl;
if (num1 = num2) {
cout << "Hey, that's a coincidence!" << endl;
}
if (num1 != num2) {
cout << "The values are not the same." << endl;
}
Exercise 1. Run the program several times using a different input each time. Does the program do what you expect? If so, explain what it is doing. If not, locate the error and fix it.
Exercise 2. Modify the program so that the user inputs both values to be tested for equality. Make sure you have a prompt for both inputs. Test the program with pairs of values that are the same and different.
Exercise 3. Modify the program so that when the numbers are the same it prints the following lines:
The values are the same.
Hey that's a coincidence.
Exercise 4. Modify the revised Exercise 3 program by replacing the two if statements with a single if/else statement. Run the program again to test the results.

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions