Advertisement
obernardovieira

Detectar se introduziu frase,número ou float

May 1st, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. /*by obernardovieira*/
  2.  
  3. #include <iostream>
  4. #include <string>
  5. //#include <cctype>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     string myStr;
  11.     cin >> myStr;
  12.  
  13.     if(myStr.find('.') != string::npos) {
  14.         cout << "é um ponto flutuante"<<endl;
  15.     }
  16.     else {
  17.         int l=0;
  18.         int len;
  19.  
  20.         len=myStr.length();
  21.         cout<<"largura "<<len<<endl;
  22.  
  23.         while(l<len) {
  24.             if(myStr[l]<0x30||myStr[l]>0x39) {
  25.             //if(!isdigit(myStr[l])) { //também funciona com a include cctype
  26.                 break;
  27.             }
  28.             l++;
  29.         }
  30.         if(l==len) {
  31.             cout<<"é um numero"<<endl;
  32.         }
  33.         else {
  34.             cout<<"é um frase"<<endl;
  35.         }
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement