Guest User

Untitled

a guest
Jan 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a = 1996; // An integer variable (a) that holds the value (1996).
  9. float b = 4.30; // A float variable (b) that holds the value (4.30).
  10.  
  11. // Using the typeid function from the <typeinfo> library to get the type of the variable
  12. // typeid(variable).name returns either i for integer
  13. // or f for float
  14. string typeOfA = typeid(a).name();
  15. string typeOfB = typeid(b).name();
  16.  
  17. cout << endl;
  18. if (typeOfA == "i") cout << "The variable a is an integer number" << endl;
  19. if (typeOfB == "f") cout << "The variable b is a floating point number (decimal)" << endl;
  20. cout << endl;
  21.  
  22. return 0;
  23. }
Add Comment
Please, Sign In to add comment