Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have written a program to read numbers between 0 to 999 but no luck to get it

ID: 3622361 • Letter: I

Question

I have written a program to read numbers between 0 to 999 but no luck to get it reads from negative -billion to +billion..

Good help will rate life saver..
I need this ASAP !!


----------------------------------------------------
Here is my program:


#include
#include

using namespace std;

// Store the words in an array
string ones [] =
{
" "," one"," two"," three"," four"," five"," six"," seven"," eight"," nine"," ten"," eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"
};

string tens [] =
{
" ", "", " twenty"," thirty"," fourty"," fifty"," sixty"," seventy"," eighty"," ninety"
};

string sayones(int n)
{
return ones[n];
}

string saytens(int n)
{
return tens[n];
}

string sayhundreds(int n)
{
return sayones(n)+" hundred";
}

string saythree(int n)
{
return sayhundreds(n)+saytens(n)+sayones(n);
}


int main()
{
int n;
cin>>n;
int> int ten = (n%100)/10;
int hun = n/100;

// Print zero if input is 0
if (n==0)
cout<<"zero"<
if (n<1000) // read number between 0-999
{
if (hun==0)
{
if (ten==1)
{
string word_form = sayones(n%100);
cout< }
else
{
string word_form = saytens(ten)+sayones(one);
cout< }
}
else
{
if (ten==1)
{
string word_form = sayhundreds(hun)+sayones(n%100);
cout< }
else
{
string word_form = sayhundreds(hun)+saytens(ten)+sayones(one);
cout< }
}
}


/*

if (n>999) // read numbers above 999 to billion
{
int billion = n/1000000000;
int million = (n/1000000)%1000;
int thousend = (n/1000)%1000;
string word = saythree(billion)+saythree(million)+saythree(thousend);
cout< cout << "You entered a number that is greater than 999" << endl;
}
*/


system("PAUSE");
return 0;
}

Explanation / Answer

please rate - thanks

don't understand that billion part, but heres from 0 to 999--message me if you'd like it to go higher

#include <iostream>
using namespace std;
void print(int);
void printword(string);
int main()
{int n;

cout<<"enter a number: ";
cin>>n;
while(n<0||n>999)
   {cout<<"Please enter positive numbers which are no more than 3 digits in length ";
    cout<<"enter a number: ";
cin>>n;
    }
print(n);
cout<<endl;
system("pause");
return 0;
}
void printword(string w)
{int i;
cout<<w;
cout<<" ";
}
void print(int num)
{int n;
string upto20[20]={"zero","one","two","three","four","five","six","seven",
                   "eight","nine","ten","eleven","twelve","thirteen",
                     "fourteen","fifteen","sixteen","seventeen",
                     "eighteen","nineteen"};

string tens[10]={"zero","ten","twenty","thirty","forty","fifty","sixty",
                 "seventy", "eighty", "ninety"};

n=num/100;
if(n>0)
     {printword(upto20[n]);
   cout<<"hundred ";
   }
num%=100;
if(num>=20)
    {n=num/10;          
        if(n>0)
           printword(tens[n]);      

     }
else if(num>=10)
    { printword(upto20[num]);
     return;
     }
num%=10;
if(num>=0)
     printword(upto20[num]);


}