Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with this C++ program Bring in the program initialize.cpp from the Les

ID: 640519 • Letter: N

Question

need help with this C++ program

Bring in the program initialize.cpp from the Lesson Set 4 source files. Follow the directions below to complete Exercise 1, Exercise 2, Exercise 3, & Exercise 4 from LAB 4.1. LAB 4.1 Relational Operators and the if Statement Exercise 1: Run the program several times using a different input each time. Does the program do what you expect? Is so, explain what it is doing. If not, locate the error and fix it. Exercise2 Modify the program so that the user inputs both values to be Exercise 2: Modify the program so that the user inputs both values to be tested for equality. Make sure you have a prompt for each input. Test the program with pairs of values that are the same and that are 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! Exxercise 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.

Explanation / Answer

For exercise 1:

The error is assignment of num2 to num1 and it is true always.

To fix it change condition to if(num1 == num2)

For exercise 2:

replace cout << "please enter integer" <<endl with cout << "please enter first integer"<<endl

after cin >> num1

add cout << "please enter second integer" <<endl; cin>> num2;

For exercise 3:

change if condition to

if(num1==num2)

{

cout<<"The values are same"<<endl;

cout<<"That's a coincidence"<<endl;

}

For exercise 4:

Replace 2 if statements with

if(num1==num2)

{

cout<<"The values are same"<<endl;

cout<<"That's a coincidence"<<endl;

}

else

cout <<"The values are not the same"<<endl;