0
0
C++programming~10 mins

Why input and output are required in C++ - Test Your Understanding

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

Complete the code to print a message to the screen.

C++
#include <iostream>

int main() {
    std::cout [1] "Hello, world!" << 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 >> instead of << for output.
Using + or -- which are not output operators.
2fill in blank
medium

Complete the code to read an integer from the user.

C++
#include <iostream>

int main() {
    int number;
    std::cout << "Enter a number: ";
    std::cin [1] number;
    std::cout << "You entered: " << number << 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 << instead of >> for input.
Using + or -- which are not input operators.
3fill in blank
hard

Fix the error in the code to correctly read and print a number.

C++
#include <iostream>

int main() {
    int value;
    std::cout << "Enter value: ";
    std::cin [1] value;
    std::cout << "Value is " << 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 << instead of >> with std::cin.
Trying to use + or -- operators for input.
4fill in blank
hard

Fill both blanks to create a program that reads a number and prints its double.

C++
#include <iostream>

int main() {
    int num;
    std::cout << "Enter number: ";
    std::cin [1] num;
    std::cout << "Double is " << num [2] 2 << 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 << instead of >> for input.
Using + instead of * for doubling.
5fill in blank
hard

Fill all three blanks to read two numbers and print their sum.

C++
#include <iostream>

int main() {
    int a, b;
    std::cout << "Enter two numbers: ";
    std::cin [1] a >> b;
    int sum = a [2] b;
    std::cout [3] "Sum is: " << sum << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A>>
B+
C<<
Attempts:
3 left
💡 Hint
Common Mistakes
Using << instead of >> for input.
Using - instead of + for addition.
Using >> instead of << for output.