diff options
| author | hybrid <hybrid@hybridlabs.cc> | 2026-08-24 00:48:14 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.cc> | 2026-08-24 00:48:14 +0300 |
| commit | e61e04619d0c9dd4d079532eff3483e234fc8acd (patch) | |
| tree | 561347af88801489977312f4cfd9b33eae75975e /src/chapter1/lesson5/q1.cpp | |
| parent | afd71cacbf324b2898220437c10b4db4228b70ce (diff) | |
| download | learncpp-e61e04619d0c9dd4d079532eff3483e234fc8acd.tar.gz learncpp-e61e04619d0c9dd4d079532eff3483e234fc8acd.tar.bz2 learncpp-e61e04619d0c9dd4d079532eff3483e234fc8acd.zip | |
add: lesson{5,6}, CMakeLists.txt
Diffstat (limited to 'src/chapter1/lesson5/q1.cpp')
| -rw-r--r-- | src/chapter1/lesson5/q1.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/chapter1/lesson5/q1.cpp b/src/chapter1/lesson5/q1.cpp new file mode 100644 index 0000000..2320bee --- /dev/null +++ b/src/chapter1/lesson5/q1.cpp @@ -0,0 +1,26 @@ +#include <iostream> // for std::cout and std::cin + +int main() +{ + std::cout << "Enter a number: "; // ask user for a number + int x{}; // define variable x to hold user input + std::cin >> x; // get number from keyboard and store it in variable x + std::cout << "You entered " << x << '\n'; + + return 0; +} + +/* + * a) 'h' is not integer type, so x will be 0. + * b) all input before '.' in '3.2' is assigned to x; all the rest remains + * for future extractions. + * c) sign character '-' is allowed, so '-3' is assigned to x + * d) same as variand a) + * e) highest acceptable value by integer type will be used if + * '99999999999999999999' is input + * f) 123 is assigned to x and 'abc' remains for future extractions + * g) first character 'a' is not a valid integer type, so extraction failed + * and x is 0 + * h) spaces droped; '+' is valid character for integer type; 5 is assigned to x + * i) 5 is assigned to x; b6 remains for future extractions +*/ |
