0
0
C++programming~10 mins

Arithmetic operators in C++ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add two numbers and print the result.

C++
#include <iostream>

int main() {
    int a = 5, b = 3;
    int sum = a [1] b;
    std::cout << sum << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using minus - instead of plus +.
Using multiplication * or division / by mistake.
2fill in blank
medium

Complete the code to calculate the remainder of division.

C++
#include <iostream>

int main() {
    int x = 10, y = 3;
    int remainder = x [1] y;
    std::cout << remainder << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A/
B+
C%
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using division / instead of remainder %.
Using multiplication * or addition + by mistake.
3fill in blank
hard

Fix the error in the code to multiply two numbers correctly.

C++
#include <iostream>

int main() {
    int a = 4, b = 7;
    int product = a [1] b;
    std::cout << product << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A*
B/
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus + or minus - instead of multiplication.
Using division / by mistake.
4fill in blank
hard

Fill both blanks to create a map of numbers to their squares for numbers greater than 3.

C++
#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;
}
Drag options to blanks, or click blank then click option'
A>
B<
C**
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than < instead of greater than >.
Using ** which is not a valid operator in C++.
5fill in blank
hard

Fill all three blanks to create a map of uppercase letters to their ASCII codes for letters with codes greater than 65.

C++
#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;
}
Drag options to blanks, or click blank then click option'
A>
Bch
Ctoupper(ch)
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than < instead of greater than >.
Using lowercase ch as value without conversion.