Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int num;
- string ones,tens,hundreds,thousands,tenthousands;
- cout << "Enter a number from 0 to 99999"<< endl ;
- cin >> num;
- int numleng = to_string(num).length(); // determine how many digits was inputted
- if(num >99999 || num < 0)
- {
- cout<< "Out of range!" << endl;
- }
- if (numleng == 1)
- {
- if(num == 0){ ones = "zero";}
- if(num == 1){ ones = "one";}
- if(num == 2){ ones = "two";}
- if(num == 3){ ones = "three";}
- if(num == 4){ ones = "four";}
- if(num == 5){ ones = "five";}
- if(num == 6){ ones = "six";}
- if(num == 7){ ones = "seven";}
- if(num == 8){ ones = "eight";}
- if(num == 9){ ones = "nine";}
- cout << ones ;
- }
- else if (numleng == 2)
- {
- if (num <= 19 && num >= 10)
- {
- if(num == 10){ tens = "ten";}
- if(num == 11){ tens = "eleven";}
- if(num == 12){ tens = "twelve";}
- if(num == 13){ tens = "thirteen";}
- if(num == 14){ tens = "fourteen";}
- if(num == 15){ tens = "fifteen";}
- if(num == 16){ tens = "sixteen";}
- if(num == 17){ tens = "seventeen";}
- if(num == 18){ tens = "eighteen";}
- if(num == 19){ tens = "nineteen";}
- cout<<tens;
- }
- else if (num <= 99 && num >=20)
- {
- if(num == 20){ tens = "twenty";}
- if(num == 30){ tens = "thirty";}
- if(num == 40){ tens = "forty";}
- if(num == 50){ tens = "fifty";}
- if(num == 60){ tens = "sixty";}
- if(num == 70){ tens = "seventy";}
- if(num == 80){ tens = "eighty";}
- if(num == 90){ tens = "ninety";}
- cout<< tens;
- }
- }
- else if (numleng == 3)
- {
- int firstnum = num % 10;
- int secnum = (num / 10) % 10;
- int thirdnum = ((num / 10) / 10) % 10;
- int gethund = (num/100)*100;
- int exception = num - gethund;
- if(exception<=19 && exception >= 10 )
- {
- if(thirdnum == 1){ hundreds = "one hundred ";}
- if(thirdnum == 2){ hundreds = "two hundred ";}
- if(thirdnum == 3){ hundreds = "three hundred ";}
- if(thirdnum == 4){ hundreds = "four hundred ";}
- if(thirdnum == 5){ hundreds = "five hundred ";}
- if(thirdnum == 6){ hundreds = "six hundred ";}
- if(thirdnum == 7){ hundreds = "seven hundred ";}
- if(thirdnum == 8){ hundreds = "eight hundred ";}
- if(thirdnum == 9){ hundreds = "nine hundred ";}
- if(exception == 10){ tens = "ten";}
- if(exception == 11){ tens = "eleven";}
- if(exception == 12){ tens = "twelve";}
- if(exception == 13){ tens = "thirteen";}
- if(exception == 14){ tens = "fourteen";}
- if(exception == 15){ tens = "fifteen";}
- if(exception == 16){ tens = "sixteen";}
- if(exception == 17){ tens = "seventeen";}
- if(exception == 18){ tens = "eighteen";}
- if(exception == 19){ tens = "nineteen";}
- cout << hundreds << tens ;
- }
- else{
- if(thirdnum == 1){ hundreds = "one hundred ";}
- if(thirdnum == 2){ hundreds = "two hundred ";}
- if(thirdnum == 3){ hundreds = "three hundred ";}
- if(thirdnum == 4){ hundreds = "four hundred ";}
- if(thirdnum == 5){ hundreds = "five hundred ";}
- if(thirdnum == 6){ hundreds = "six hundred ";}
- if(thirdnum == 7){ hundreds = "seven hundred ";}
- if(thirdnum == 8){ hundreds = "eight hundred ";}
- if(thirdnum == 9){ hundreds = "nine hundred ";}
- if(secnum == 2){ tens = "twenty";}
- if(secnum == 3){ tens = "thirty";}
- if(secnum == 4){ tens = "forty";}
- if(secnum == 5){ tens = "fifty";}
- if(secnum == 6){ tens = "sixty";}
- if(secnum == 7){ tens = "seventy";}
- if(secnum == 8){ tens = "eighty";}
- if(secnum == 9){ tens = "ninety";}
- if(firstnum == 0){ ones = "";}
- if(firstnum == 1){ ones = "one";}
- if(firstnum == 2){ ones = "two";}
- if(firstnum == 3){ ones = "three";}
- if(firstnum == 4){ ones = "four";}
- if(firstnum == 5){ ones = "five";}
- if(firstnum == 6){ ones = "six";}
- if(firstnum == 7){ ones = "seven";}
- if(firstnum == 8){ ones = "eight";}
- if(firstnum == 9){ ones = "nine";}
- cout << hundreds << tens << " " << ones ;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement