You can read into a string and check if it contains the decimal separator. Assuming it is '.', here's an example implementation:
#include <iostream>
#include <string>
int main()
{
std::string s;
std::cin >> s;
std::cout << ((s.find('.') == std::string::npos) ? "integer" : "double") << std::endl;
return 0;
}
You also have to check for exponents (like 2e-1
). Here's one way to do it all:
#include <iostream>
#include <string>
int main()
{
std::string s;
std::cin >> s;
if (s.find_first_of(".,eE") == std::string::npos)
std::cout << "integer" << std::endl;
else
std::cout << "double" << std::endl;
return 0;
}