I have to create a program that asks a person to enter numbers (1-99) and convert it into words. I've been working on this for days and I still don't see what I'm doing wrong! PLEASE HELP ME!!!
I get an error on all the case numbers and I dont understand what is wrong.
EXAMPLE:
using namespace std;
27
twenty-seven
#include <string>
//function prototypes go here
int main()
{
int input;
cout << "Please enter a positive integer: ";
cin >> input;
cout << intName(input) << endl;
cout << endl;
system("pause");
return EXIT_SUCCESS;
}
string intName(int number)
{
int part = number; //The part that still needs to be converted
string name; //The return value
if (part >= 100)
{
name = digitName(part / 100) + " hundred";
part = part % 100;
}
if (part >= 20)
{
name = name + " " + tensName(part);
part = part % 10;
}
else if (part >= 10)
{
name = name + " " + teenName(part);
part = 0;
}
if (part > 0)
{
name = name + " " + digitName(part);
}
return name;
}
/*
Turns a digit into its English name
@param an integer btw 1 and 9
@return the name of digit( "one" ... "nine" )
*/
string digitName(int digit)
{
case 0:
cout << " ";
break;
case 1:
cout << "one";
break;
case 2:
cout << "two";
break;
case 3:
cout << "three";
break;
case 4:
cout << "four";
break;
case 5:
cout << "five";
break;
case 6:
cout << "six";
break;
case 7:
cout << "seven";
break;
case 8:
cout << "eight";
break;
case 9:
cout << "nine";
break;
default:
cout << " Error ";
}
/*
Turns a number btw 10 and 19 into its English name.
@param number an integer btw 10 and 19
@return the name of the given number( "ten" ... "nineteen")
*/
string teenName(int number)
{
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 ";
}
/*
Gives the name of the tens part of a number btw 20 and 99
@param number an integer btw 20 and 99
@return the name of the tens part of the number( "twenty" ... "ninety")
*/
string tensName(int number)
{
case 2: cout << “Twenty”;
break;
case 3: cout << “Thirty”;
break;
case 4: cout << “Fourty”;
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;
}