Advertisement
Ashanmaril

Four (C++ translation)

Sep 18th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string words[] = {
  7.     "Zero",
  8.     "One",
  9.     "Two",
  10.     "Three",
  11.     "Four",
  12.     "Five",
  13.     "Six",
  14.     "Seven",
  15.     "Eight",
  16.     "Nine",
  17.     "Ten",
  18.     "Eleven",
  19.     "Twelve",
  20.     "Thirteen",
  21.     "Fourteen",
  22.     "Fifteen",
  23.     "Sixteen",
  24.     "Seventeen",
  25.     "Eighteen",
  26.     "Nineteen",
  27.     "Twenty",
  28.     "Twentyone",
  29.     "Twentytwo",
  30.     "Twentythree",
  31.     "Twentyfour",
  32.     "Twentyfive",
  33.     "Twentysix",
  34.     "Twentyseven",
  35.     "Twentyeight",
  36.     "Twentynine",
  37.     "Thirty",
  38.     "Thirtyone",
  39.     "Thirtytwo",
  40.     "Thirtythree",
  41.     "Thirtyfour",
  42.     "Thirtyfive",
  43.     "Thirtysix",
  44.     "Thirtyseven",
  45.     "Thirtyeight",
  46.     "Thirtynine",
  47.     "Forty",
  48.     "Fortyone",
  49.     "Fortytwo",
  50.     "Fortythree",
  51.     "Fortyfour",
  52.     "Fortyfive",
  53.     "Fortysix",
  54.     "Fortyseven",
  55.     "Fortyeight",
  56.     "Fortynine",
  57.     "Fifty"
  58. };
  59.  
  60. int maxNumber = sizeof(words) / sizeof(words[0]) - 1;
  61.  
  62. string numToStr(int num)
  63. {
  64.     return words[num];
  65. }
  66.  
  67. int main()
  68. {
  69.     int theNum = 0;
  70.  
  71.     do
  72.     {
  73.         cout << "Input a number between 0 and " << maxNumber << endl;
  74.         cin >> theNum;
  75.     } while (theNum < 0 || theNum > maxNumber);
  76.  
  77.     while (theNum != 4)
  78.     {
  79.         int temp = numToStr(theNum).length();
  80.         cout << numToStr(theNum) << " is " << numToStr(temp) << endl;
  81.         theNum = temp;
  82.     };
  83.  
  84.     cout << "Four is the magic number" << endl;
  85.  
  86.     return 0;
  87. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement