Advertisement
informaticage

NumToString

Sep 15th, 2014
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8.        
  9.    
  10.         int num,c1,c2;
  11.         string u[] = {"zero", "uno" , "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove" };
  12.         string d[] = {"dieci", "undici", "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove"};
  13.         string nd[] = {"venti", "trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta"};
  14.         cout << "Inserire numero in cifre:(0-99)" << endl;
  15.         cin >> num;
  16.         c1 = (num / 10);
  17.         c2 = num - (c1 * 10);
  18.         /**********************************************************************/
  19.         if (num < 10)
  20.             cout << u[num] << endl;
  21.         else
  22.             if (num > 10 && num < 20)
  23.                 cout << d[c2] << endl;
  24.             else
  25.                 if (num > 20 && num < 100)
  26.                     cout << nd[c1 - 2] << u[c2] << endl;
  27.                 else
  28.                     cout << "Valore non valido! " << endl;
  29.         /**********************************************************************/
  30.         system("pause >>null");
  31.         return EXIT_SUCCESS;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement