Skip to content

Input

1
#include <iostream>

1
2
3
int age;
std::cout << "How old are you? ";
std::cin >> age;

1
2
3
4
5
std::cout << "How old are you again? ";
if (!(std::cin >> age)) {
    std::cout << "There is an error in your input\n";
    return 1;
}

1
2
3
4
5
6
if (age >= 18) {
    std::cout << "Welcome!\n";
} else {
    std::cout << "Sorry.\n";
    return 1;
}

Share Snippets