Wednesday, 20 January 2016

// // Leave a Comment

CONVERTING INTO WORDS

C++ Program Which Convert Number Into Words 

#include <iostream>
using namespace std;
int main()
{
int num, one, ten, hundred, b;

cout << "Enter a  number between 1 to 1000:\n";
cin >> num;
hundred = num / 100;//1st
b = num % 100;//
ten = b / 10;//2nd
one = b % 10;//3rd

if (hundred >= 1 && hundred <= 10)
{

switch (hundred)

{
case 0:
break;
case 1:
cout << "one hundred";
break;
case 2:
cout << " two hundred ";
break;
case 3:
cout << " three hundred ";
break;
case 4:
cout << " four hundred ";
break;
case 5:
cout << " five hundred ";
break;
case 6:
cout << " six hundred ";
break;
case 7:
cout << " seven hundred ";
break;
case 8:
cout << " eight hundred ";
break;
case 9:
cout << " nine hundred ";
break;
case 10:
cout << "one thousand ";
break;
default:
cout << " Error ";
}
}
if (b >= 10 && b <= 19)
{

switch (num)
{

case 10:
cout << "Ten";
break;
case 11:
cout << "Eleven";
break;
case 12:
cout << "Twelve";
break;
case 13:
cout << "Thirteen";
break;
case 14:
cout << "Fourteen";
break;
case 15:
cout << "Fifteen";
break;
case 16:
cout << "Sixteen";
break;
case 17:
cout << "Seventeen";
break;
case 18:
cout << "Eighteen";
break;
case 19:
cout << "Nineteen";
break;
default:
cout << " Error ";

}
}
else {

switch (ten)
{
case 0:
break;
case 2:
cout << " twenty";
break;
case 3:
cout << " thirty ";
break;
case 4:
cout << " forty ";
break;
case 5:
cout << " fifty ";
break;
case 6:
cout << " sixty ";
break;
case 7:
cout << " seventy ";
break;
case 8:
cout << " eighty ";
break;
case 9:
cout << " ninety ";
break;
default:
cout << " Error ";
}
switch (one)
{
case 0:
cout << " " << endl;
break;
case 1:
cout << "one" << endl;
break;
case 2:
cout << "two" << endl;
break;
case 3:
cout << "three" << endl;
break;
case 4:
cout << "four" << endl;
break;
case 5:
cout << "five" << endl;
break;
case 6:
cout << "six" << endl;
break;
case 7:
cout << "seven" << endl;
break;
case 8:
cout << "eight" << endl;
break;
case 9:
cout << "nine" << endl;
break;
default:
cout << " Error "<<endl;
}
}


system("pause");
}



0 comments:

Post a Comment