I know how to give the leftmost digit when i am already given a number but when there has to be a random number entered into the cin space, i am not sure how to do it. I know to find leftmost of a three digit number you modulus it by 100. Here is some of my code.
#include <iostream>
usingnamespace std;
int main()
{int a,b;
cout << "Please enter a 3-digit number." << endl;
cin >> a;
if (a ==100 || a> 100)
{
cout <<"" << endl;
cin.get();
}
else
{
cout << "Invalid input, please run the program again and enter a 3-digit number.";
cin.get();
}
if (a % 2 == 1)
{
cout << " The number is odd" << endl;
}
else
{
cout << "The number is even" << endl;
cin.get();
}
if (a%100 ==0)
{
cout<< "The number is divisible by 100." << endl;
}
else
{
cout<< "The number is not divisible by 100." << endl;
}
if(a %100 ==)
cin.get();
return 0;
}
A is the number that is going to be entered. I know it would look something like
if(number%100 == ?)
I put the question mark cause i dont know what i would put here.
I cant put leftmost because it says when i tried that leftmost is uninitialized
int left_most_digit( unsignedlonglong number )
{
if( number < 10 ) return number ; // single digit number; return the digit
elsereturn left_most_digit( number/10 ) ; // return the left-most digit of the
// digits except the last digit
}