0
0
C++programming~10 mins

Multiple input and output 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 read two integers from input.

C++
#include <iostream>

int main() {
    int a, b;
    std::cin >> [1] >> b;
    std::cout << a + b << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Aa
Bc
Cx
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared.
Mixing variable names.
2fill in blank
medium

Complete the code to output the product of two integers.

C++
#include <iostream>

int main() {
    int x = 4, y = 5;
    std::cout << x [1] y << 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 addition instead of multiplication.
Using division or subtraction by mistake.
3fill in blank
hard

Fix the error in the code to correctly read three integers and output their sum.

C++
#include <iostream>

int main() {
    int a, b, c;
    std::cin >> a >> b >> [1];
    std::cout << a + b + c << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Ad
Bc
Ce
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared.
Typo in variable name.
4fill in blank
hard

Fill both blanks to read two floats and output their average.

C++
#include <iostream>

int main() {
    float [1], [2];
    std::cin >> a >> b;
    std::cout << (a + b) / 2 << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Aa
Bb
Cx
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Declaring variables different from those used in input.
Using undeclared variables.
5fill in blank
hard

Fill all three blanks to read three integers and output their maximum.

C++
#include <iostream>
#include <algorithm>

int main() {
    int [1], [2], [3];
    std::cin >> x >> y >> z;
    int max_val = std::max([1], std::max([2], [3]));
    std::cout << max_val << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Ax
By
Cz
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using undeclared variables.
Mixing variable names between declaration and usage.