This is an array string problem where I have to ask for a sentence input that includes an integer (between 0 and 9), then the program has to change that integer to its name in words.
Like: This is test 3.
Would say: This is test three.
My program does it, but it includes many nested if statements, so I want to know if there is a shorter way to do it. Also, can I do it for any sentence length?
Or do I have to tell the user how long it has to be?
For this program i did it as if the user is going to enter a sentence 6 words long or less!
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
int size=6;
string sentence[size];
string done;
cout<<"enter a sentence that includes a number:"<<endl;
for (int n=0; n<size; n++)
cin>>sentence[n];
for(int i=0; i<size; i++)
{
if (sentence[i]=="0")
{sentence[i]="zero";
}
else
{
if(sentence[i]=="1")
{sentence[i]="one";
}
else
{
if (sentence[i]=="2")
{ sentence[i]="two";
}
else
{ if (sentence[i]=="3")
{sentence[i]="three";
}
else
{
if (sentence[i]=="4")
{sentence[i]="four";
}
else
{
if(sentence[i]=="5")
{sentence[i]="five";
}
else
{
if(sentence[i]=="6")
{sentence[i]="six";
}
else
{
if (sentence[i]=="7")
{sentence[i]="seven";
}
else
{
if(sentence[i]=="8")
{sentence[i]="eigth";
}
else
{
if(sentence[i]=="9")
{sentence[i]="nine";
}
}
}
}
}
}
}
}
}
}
cout<<sentence[i]<<" ";
}
system("PAUSE");
return EXIT_SUCCESS;
}