I'm trying to print the first digit of the inputted number, but the output comes out as zero. Why is this not working?
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
int n;
int count = 0;
cout<<"enter the number: ";
cin>>n;
while(n!=0){
n=n/10;
count=count + 1;
}
cout<<"number of digits in your number are: "<<count<<endl;
int z = pow(10, count-1);
int first = n/z;
cout<<"the first digit of your number is: "<<first<<endl;
return 0;
}