0

Hey guys...

I want to write a program that transforms numbers into letters and letters into numbers...

for example 20 would be transformed into twenty

I have this but I don't know what's missing or what's the problem... help please

#include <iostream>
#include <string>

using namespace std;
using std::string;
void ones(string);

int main(){


int number;


cout<<"ENter:"<<endl;
cin>>number;

switch(number.length())
{
case 1: ones(number);


}

system("pause");
return 0;


}

void ones(int numero)
{
int x;
x=atoi (numero);

switch(x)
{
case 1: cout<<"one"<<endl;
case 2: cout<<"two"<<endl;
case 3: cout<<"three"<<endl;
case 4: cout<<"four"<<endl;
case 5: cout<<"five"<<endl;
case 6: cout<<"six"<<endl;
case 7: cout<<"seven"<<endl;
case 8: cout<<"eight"<<endl;
case 9: cout<<"nine"<<endl;
case 0: cout<<"zero"<<endl;

}

}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by rati
0

You have number declared as an integer, but you are treating it as a string. There is no "int" class, so you cannot use the dot operator as you do in line 17. Use an if statement instead of the switch statement on line 17:

if (number >= 0 && number < 10)
   ones(number);
0

And please dont use

system("pause");

it is not a good approach.. use getch etc instead :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.