This question already has an answer here:
So i've been trying to make a program that counts number of digits entered by it's user as long as the value is less than 10 billion, but i can't seem to get it to work properly, so far it counts the number of digits entered but it does not recognise if the value is greater or less than 10billion instead it just ignores the loop in the code and prints out"10" for every value entered that's greater than 10billion. I've tried everything i can think of(im pretty new to programming and all so excuse my errors if any) :C
#include <iostream>
using namespace std;
int main(){
long n;
cout<<"Enter a number less than 10billion:";
cin>>n;
if (( n>=10000000000 || ( n<-0 ))) {
cout<< endl <<"Number exceeds the range"<< endl;
}
else{
int count=0;
while(n>0){
n=n/10;
count++;
}
cout<<"Total number of digits="<<count;
return 0;
}
}
Aucun commentaire:
Enregistrer un commentaire