Q. Write a program which asks the user to enter a bunch of numbers (Mobile numbers) and each number should be listed under specific categories (Country names) according to the very first 3 digits (area code)
For example, 111 US, 100 UK, 555 Spain.. Based on such information we should detect each number where it belongs to.
The thing is that they did not mention how many digits those numbers make. Which makes it hard for me to find a way other than the traditional one.
(assume each number consists of 5 digits and area code is 640)
if(number>= 64000 && x<64100)...
But that's not that case, and hence why I'm here seeking your help. Thanks.
#include <iostream>
int first_three_digits_of( unsignedlonglong number )
{
// chop off digits on the right till only three digits are left
while( number > 999 ) number /= 10 ;
return number ;
}
int main()
{
unsignedlonglong number ;
while( std::cout << "number? " && std::cin >> number )
std::cout << first_three_digits_of(number) << '\n' ;
}