Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Intermediate Accounting

Authors: Donald E. Kieso, Jerry J. Weygandt, And Terry D. Warfield

13th Edition

9780470374948, 470423684, 470374942, 978-0470423684

Students also viewed these Databases questions