Complete the code to add two numbers 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 plus +.* or division / by mistake.The plus sign + adds two numbers together.
Complete the code to calculate the remainder of division.
#include <iostream> int main() { int x = 10, y = 3; int remainder = x [1] y; std::cout << remainder << std::endl; return 0; }
/ instead of remainder %.* or addition + by mistake.The percent sign % gives the remainder after division.
Fix the error in the code to multiply two numbers correctly.
#include <iostream> int main() { int a = 4, b = 7; int product = a [1] b; std::cout << product << std::endl; return 0; }
+ or minus - instead of multiplication./ by mistake.The asterisk * is the multiplication operator in C++.
Fill both blanks to create a map of numbers to their squares for numbers greater than 3.
#include <iostream> #include <map> int main() { std::map<int, int> squares; for (int num = 1; num <= 5; ++num) { if (num [1] 3) { squares[num] = num [2] num; } } for (const auto& [key, value] : squares) { std::cout << key << ": " << value << std::endl; } return 0; }
< instead of greater than >.** which is not a valid operator in C++.The condition num > 3 selects numbers greater than 3. The multiplication operator * squares the number.
Fill all three blanks to create a map of uppercase letters to their ASCII codes for letters with codes greater than 65.
#include <iostream> #include <map> #include <cctype> int main() { std::map<char, int> letter_codes; for (char ch = 'A'; ch <= 'E'; ++ch) { if (static_cast<int>(ch) [1] 65) { letter_codes[[2]] = static_cast<int>([3]); } } for (const auto& [letter, code] : letter_codes) { std::cout << letter << ": " << code << std::endl; } return 0; }
< instead of greater than >.ch as value without conversion.The condition ch > 65 checks ASCII codes greater than 65. The key uses ch and the value uses toupper(ch) to ensure uppercase letters.