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...).
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;
}