Elysia and antred,
Thank you for your comments.
First, Elysia, thank you for thinking I know what I am doing. I am throwing things in the dark and seeing if they stick as anything else.
Second, antred, I have removed the const attribute. Question, when would it be advantageous to use the const?
Third, I have put the final project below. Would I still not need the global variables?
Code:
#include <iostream>
#include <string>
using namespace std;
int numpn;
int numpn2;
int onesPrint;
int num;
int ones;
int tens;
int hund;
int thou;
int ttho;
int htho;
int mill;
void printTwenty (int tens);
char ifNegative ()// gives back an absolute value of numpn
{
if ( numpn < 0)
{
cout << "Negative";
return numpn2 = (numpn * -1);
}
else if (numpn > 0)
{
return numpn2 = (numpn * 1);
}
else
{
return 0;
}
}
void printOnes ( int ones)// trying to print the word of the number, here trying to pass the int mill to the function
{
switch (ones)
{
case 9:
cout << " nine";
break;
case 8:
cout << " eight";
break;
case 7:
cout << " seven";
break;
case 6:
cout << " six";
break;
case 5:
cout << " five";
break;
case 4:
cout << " four";
break;
case 3:
cout << " three";
break;
case 2:
cout << " two";
break;
case 1:
cout << " one";
break;
default :
break;
}
}
void printMill (int mill)
{
int ones = mill;
printOnes(ones);
}
void printHtho (int htho)
{
int ones = htho;
printOnes(ones);
}
void printTtho (int ttho)
{
int tens = ttho;
printTwenty(tens);
}
void printHund (int hund)
{
int ones = hund;
printOnes (ones);
cout << " hundred";
}
void printTwenty (int tens)
{
switch (tens)
{
case 9:
cout << " ninety";
break;
case 8:
cout << " eighty";
break;
case 7:
cout << " seventy";
break;
case 6:
cout << " sixty";
break;
case 5:
cout << " fifty";
break;
case 4:
cout << " forty";
break;
case 3:
cout << " thirty";
break;
case 2:
cout << " twenty";
break;
default :
break;
}
}
void printTeens ( int ones)
{
switch (ones)
{
case 9:
cout << " nineteen";
break;
case 8:
cout << " eighteen";
break;
case 7:
cout << " seventeen";
break;
case 6:
cout << " sixteen";
break;
case 5:
cout << " fifteen";
break;
case 4:
cout << " fourteen";
break;
case 3:
cout << " thirteen";
break;
case 2:
cout << " twelve";
break;
case 1:
cout << " eleven";
break;
default :
break;
}
}
void printThouTeens ( int ones)
{
printTeens(ones);
}
int main()
{
cout << "Please enter a number less than two billion and more then negative two billion" << "\n";
cin >> numpn; // input
ifNegative (); // changing to absolute value of input
int ones = numpn2 % 10 / 1;
int tens = numpn2 % 100 / 10;
int hund = numpn2 % 1000 / 100;
int thou = numpn2 % 10000 / 1000;
int ttho = numpn2 % 100000 / 10000;
int htho = numpn2 % 1000000 / 100000;
int mill = numpn2 % 10000000 / 1000000;// separating the input into addressable digits with names
//cout << ones << "\n";
//cout << tens << "\n";
//cout << hund << "\n";
//cout << thou << "\n";
//cout << ttho << "\n";
//cout << htho << "\n";
//cout << mill << "\n";// showing that I have done that
if (numpn == 0)
{
cout << "Zero";// starting by changing a 0 input to Zero and stopping (numpn is still around)This works
}
if ( mill != 0 )
{
printMill ( mill);
cout << " million,";
}
if ( htho != 0)
{
printHtho ( htho);
cout << " hundred";
}
if (ttho != 0 && ttho != 1)
{
int tens = ttho;
printTwenty(tens);
}
if (thou != 0 && ttho != 1)
{
int ones = thou;
printOnes(ones);
cout << " thousand,";
}
if (ttho == 1)
{
int ones = thou;
printTeens ( ones );
cout << " thousand,";
}
if (hund != 0)
{
printHund (hund);
}
if (tens != 0 && tens != 1)
{
printTwenty( tens);
}
if (tens == 1 )
{
printTeens ( ones);
}
if (ones != 0 && tens != 1)
{
printOnes(ones);
}
}