#include<iostream>
using namespace std;
//forward declarations
int power_of_ten(int);
int input();
int num_count(int&);
void new_val(int&);
int main()
{
int string_of_numbers{0};
do
{
string_of_numbers=input();
cout << endl; //spacing
new_val(string_of_numbers);
cout << endl; //spacing
cout << endl; //spacing
system("pause");
system("cls");
}while(string_of_numbers != -1); // loop until user enters -1
}
int input()
{
int num_to_string;
cout << "Insert or '-1' to quit: ";
cin >> num_to_string;
return num_to_string;
}
int num_count(int &string_of_numbers)
{
int sub_string_of_numbers{string_of_numbers};
int amount{0};
while(sub_string_of_numbers>0)
{
sub_string_of_numbers=sub_string_of_numbers/10;
amount++;
}
return amount;
}
void new_val(int &string_of_numbers)
{
int m[100]={0};
int i{0};
int count_n{0};
//added if else checks for input to set count_n variable
if (string_of_numbers == 0)
count_n = 0;
else
count_n = num_count(string_of_numbers)-1;
for(i = 0; count_n > (-1); i++)
{
int exponents = power_of_ten(count_n); //added function call and set to exponents variable
//added if else checks to set array of integers
if(string_of_numbers == 0)
{
m[i] = 0;
}
else if (count_n == 0)
{
m[i]=string_of_numbers;
}
else
{
m[i]=string_of_numbers / exponents;
}
switch(m[i])
{
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;
}
string_of_numbers %= exponents;
count_n--;
}
}
// function for power of 10s
int power_of_ten(int x)
{
int power_of_tens = 10;
for(int j = 1; j < x; ++j)
{
power_of_tens *= 10;
}
return power_of_tens;
}