So I have been writing a code and I am trying to get it to spell out word by word using the numbers I entered. say I enter '-000000000000026450' I would like to display "-26450" is "minus two six four five zero"' I can only get it to print single numbers at the moment(-2 writes out minus 2) NOT using nested loops.
any idea?
[code]
int main()
{
int number, i = 0, absolutenumber, ones;
//char * word[1000];
cout << "Enter any integer\n ";
cin >> number;
if (number < 0)
{
cout << "minus ";
}
absolutenumber = abs(number);
{
// tens = (absolutenumber / 10) % 10;
ones = absolutenumber % 10;
switch (ones) {
case 0: cout << "zero ";
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;
}
}
cout<< number << " spelled out is"<<...<< endl;
thanks, I atempted to run it and it generated an error for itoa
Severity Code Description Project File Line Suppression State
Error C4996 'itoa': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _itoa. See online help for details. ConsoleApplication5 c:\users\owner\documents\visual studio 2015\projects\console1\lesson 2\consoleapplication5\consoleapplication5\source.cpp 20
okay it ran!! would you have any idea how to get it to print all on the same line?
'-123' is minus one two three.
not '-123' is
minus one two three do you understand what i mean?