Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
