Question: Learning Objectives: After completing this lab the student will be able to: Use the relational and logical operators to write conditional expressions. Write if statements

Learning Objectives: After completing this lab the student will be able to:
Use the relational and logical operators to write conditional expressions.
Write if statements to select a block to be executed when a conditional expression is true.
Write if-else statements to select one block or a different block to execute based on the result of a conditional
expression.
Part 1 Relational Operators and the If Statement
In your C++ IDE, create a new project named Lab 5 Part 1, or something similar. Add a C++ source code file named lab5-
1.cpp to the project. Then copy-and-paste the code below into lab5-1.cpp.
//******************************************************************************
// PROJECT: Lab 5 Part 1
// FILE: lab5-1.cpp
//
// DESCR: This project will help you learn the difference between the C++
// assignment operator = and the C++ relational equality operator ==.
// They are completely different operators and they work in completely
// different ways.
//
// AUTHOR: Your Name
// DATE: The date the project is completed or published
//******************************************************************************
#include
using namespace std;
int main()
{
int num1; // num1 is not initialized
int num2=5; // num2 has been initialized to 5
cout << "Please enter an integer" << endl;
cin >> num1;
cout << "num1="<< num1<<" and num2="<< num2<< endl;
if (num1= num2)
cout << "Hey, thats a coincidence!" << endl;
if (num1!= num2)
cout << "The values are not the same" << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This is an introduction to using relational and logical operators in C and implementing conditional logic in programs using if and ifelse statements I... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!