Complete the code to add two integers and print the result.
#include <iostream> int main() { int a = 5, b = 3; int sum = a [1] b; std::cout << sum << std::endl; return 0; }
- instead of addition.* or division / by mistake.The + operator adds two numbers. Here, it adds a and b to get the sum.
Complete the code to compare if two numbers are equal.
#include <iostream> int main() { int x = 10, y = 10; if (x [1] y) { std::cout << "Equal" << std::endl; } else { std::cout << "Not equal" << std::endl; } return 0; }
= instead of comparison ==.!= by mistake.The == operator checks if two values are equal. It returns true if they are the same.
Fix the error in the code to multiply two numbers correctly.
#include <iostream> int main() { int a = 4, b = 5; int product = a [1] b; std::cout << product << std::endl; return 0; }
+ or subtraction - instead of multiplication./ by mistake.The * operator multiplies two numbers. Using it here calculates the product of a and b.
Fill both blanks to create a dictionary-like structure using a map and check if a key exists.
#include <iostream> #include <string> #include <map> int main() { std::map<std::string, int> scores; scores["Alice"] = 90; if (scores.[1]("Alice") [2] scores.end()) { std::cout << "Alice's score is " << scores["Alice"] << std::endl; } return 0; }
count method incorrectly here.== instead of not equal !=.The find method searches for a key in the map. If the result is not equal (!=) to end(), the key exists.
Fill all three blanks to create a conditional expression that checks if a number is positive, negative, or zero.
#include <iostream> #include <string> int main() { int num = -5; std::string result = (num [1] 0) ? "Positive" : ((num [2] 0) ? "Negative" : (num [3] 0 ? "Zero" : "Error")); std::cout << result << std::endl; return 0; }
!= instead of equal == for zero check.The first blank uses > to check if num is positive. The second uses < to check if negative. The third uses == to check if zero.