Search⌘ K

Solution Review: Find the Person with the Highest Salary

Explore how to determine the person with the highest salary by applying conditional if-else statements in C++. Understand each step of the code and its logic, helping you solidify your grasp of decision-making structures in C++ programming.

We'll cover the following...

Solution #

Run the code below and see the output!

C++
#include <iostream>
using namespace std;
int main() {
// Initialize variable salary1 and salary2
int salary1 = 56;
int salary2 = 89;
// if condition
if (salary1 > salary2) {
// if body
cout << "person1";
} else {
// else body
cout << "person2";
}
// exit
return 0;
}

Explanation

Line No. 7 ...