When I input 990 output prints as Nine Hundred Ninety Nine Zero.
What is my mistake?
#include <iostream>
#include <string>
using namespace std;
void converttowords (int n);
int main()
{
int num;
system("cls");
cout<<"Enter a digit from 0-99: ";
cin>>num;
converttowords(num);
}
void converttowords (int n)
{
const char *ones[10]={"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
const char *teens[20]={"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
const char *tens[10]={" ", " ","Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
if (n<0||n>999)
{
cout<<"Out of range";
cout<<endl;
}
else if (n<=9)
{
cout<<ones[n%10];
}
else if (n<=19)
{
cout<<teens[n%10];
}
else if (n>=100 && n<=999)
{
cout<<ones[n/100];
cout<<" Hundred ";
cout<<tens[(n%100)/10]<<" "<<ones[n%10];
}
else if (n%100 <= 19 && n%100 >= 10)
{
cout<<teens[n%10];
}
else
{
cout<<tens[n/10];
}
cout<<endl;
system ("pause");
}
We're from St. Paul University Manila.
CSIT students incoming 2nd year(if we pass) xD
This is our Course Requirement if Programming 1. In that case
our questions/codes are same. :)