#include<iostream.h>
using namespace std;

char*ones(int number){
    int num = number&&100;
    if(num>10&&num<20){
    return "";
    }
    else {
    num = num%10;
    switch (num){
    case 1:
        return "one";
    case 2:
        return "two";
    case 3:
        return "three";
    case 4:
        return "four";
    case 5:
        return "five";
    case 6:
        return "six";
    case 7:
        return "seven";
    case 8:
        return "eight";
    case 9:
        return "nine";
    default:
    return "";
    }
}
}
char*tens(int number){
    int num=number%100;
    if (num>9&&num<20){
    switch (num){

    case 10:
        return "ten";
    case 11:
        return "eleven";
    case 12:
        return "twelve";
    case 13:
        return "thirteen";
    case 14:
        return "fourteen";
    case 15:
        return "fifthteen";
    case 16:
        return "sixteen";
    case 17:
        return "seventeen";
    case 18:
        return "eighteen";
    case 19:
        return "nineteen";
    default:
    return "";
    }
}
else{
switch (num/10){
    case 1:
        return "ten";
    case 2:
        return "twenty";
    case 3:
        return "thirty";
    case 4:
        return "fourty";
    case 5:
        return "fifty";
    case 6:
        return "sixty";
    case 7:
        return "seventy";
    case 8:
        return "eighty";
    case 9:
        return "ninety";
    default:
    return "";
    }
}
}
char*hundredths(int number){
int num = (number%1000)/100;
switch (num){
    case 1:
        return "one hundred";
    case 2:
        return "two hundred";
    case 3:
        return "three hundred";
    case 4:
        return "four hundred";
    case 5:
        return "five hundred";
    case 6:
        return "six hundred";
    case 7:
        return "seven hundred";
    case 8:
        return "eight hundred";
    case 9:
        return "nine hundred";
    default:
    return "";
    }
}

char*thousands(int number){
int num =number/1000;
switch (num){
    case 1:
        return "one thousand";
    case 2:
        return "two thousand";
    case 3:
        return "three thousand";
    case 4:
        return "four thousand";
    case 5:
        return "five thousand";
    case 6:
        return "six thousand";
    case 7:
        return "seven thousand";
    case 8:
        return "eight thousand";
    case 9:
        return "nine thousand";
    default:
    return "";
    }
}

int main(){
int yes=1;
while (yes){
int num;
cout<<"_________________________________________________________________"<<endl;
cout<<"This will output number to its equivalent word"<<endl;
cout<<"_________________________________________________________________\n\n\n"<<endl;
cout<<"enter the number:";
cin>>num;
if(num==0){
    cout<<"\n\nThe number"<<num<<"in words is:";
    cout<<"zero\n\n";
    cout<<"try again?y/n:";
    }
    else if(num<=9000&&num>=1){
    cout<<"\n\nThe number"<<num<<"in words is:";
    cout<<thousands(num)<<hundredths(num)<<tens(num)<<ones(num)<<endl<<endl;
    cout<<"try again?y/n:";
    }
    else{
    cout<<"\n\nnumber out of range\n\n";
    cout<<"try again?y or n:"
    }
    char ans;
    cin>>ans;
    if (ans=='y'||ans=='Y')
    yes=1;
    else
    yes=0;
    system("cls");
    }
    return 0;
    }

this was a program converting from number to word.. still not complete and still has an 4 errors n 1 warning... declaration syntax error and missing statement... sumbody has an idea their??

Recommended Answers

All 2 Replies

Maybe, try using code tags so we can see it better.

hi,
you were missing a semicolon ";" here in your else statement

else
{
    cout<<"\n\nnumber out of range\n\n";
    cout<<"try again?y or n:" ; <-include the brace as I have done
}

also, dont include ".h" in your header

#include<iostream>

also, no matter what number I type, it always says thirtyone, but yet again, you said it was incomplete so...good luck =]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.