0

If and "cin"

Can somebody write a c++ code with if and else statement with the "cin" command? For example: I will insert a number, and the program will show it is 2 digits(10,11,12,13....) or 1 digit(0,1,2,3,4...).

5th Oct 2018, 12:51 PM
TheDoctor
TheDoctor - avatar
2 Antworten
+ 9
#include <iostream> #include <cmath> using namespace std; int main() { int num = 0; cin >> num; cout << "Entered number: " << num << endl; int digits = floor(log10(num) + 1); cout << num << " has " << digits << " digit(s) in it\n"; return 0; }
5th Oct 2018, 1:14 PM
blACk sh4d0w
blACk sh4d0w - avatar
5th Oct 2018, 1:17 PM
can_be_better
can_be_better - avatar