Hey all
I'm trying to create a program that takes a predetermined number (monthly salary in this case) and rather than printing as a number it prints it as text. However when I input a number all I get is random stuff that makes no sence.
I will include the code and also a link to a screenshot of what I see.
Link to picture of the problem
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int main(int argc, char *argv[])
{
int inum;
cout <<"enter the number";
cin >> inum;
int iquo, irem;
iquo = inum / 100;
irem = inum % 100;
char *cdisp;
cdisp = new char[200];
if( inum < 0)
{
strcat(cdisp, "minus");
inum = 0 - inum;
}
if(irem >=10 && irem < 20)
{
switch (irem)
{
case 11:
strcat(cdisp," eleven");
break;
case 12:
strcat(cdisp," twelve");
break;
case 13:
strcat(cdisp," thirteen");
break;
case 14:
strcat(cdisp," fourteen");
break;
case 15:
strcat(cdisp," fifteen");
break;
case 16:
strcat(cdisp," sixteen");
break;
case 17:
strcat(cdisp," seventeen");
break;
case 18:
strcat(cdisp," eighteen" );
break;
case 19:
strcat(cdisp," nineteen");
break;
}
}
if(irem >= 20)
{
switch (irem)
{
case 20:
strcat(cdisp," twenty");
break;
case 30:
strcat(cdisp," thirty");
break;
case 40:
strcat(cdisp," fourty");
break;
case 50:
strcat(cdisp," fifty");
break;
case 60:
strcat(cdisp," sixty");
break;
case 70:
strcat(cdisp," seventy");
break;
case 80:
strcat(cdisp," eighty");
break;
case 90:
strcat(cdisp,"ninety" );
break;
}
irem = irem %10;
switch (irem)
{
case 1:
strcat(cdisp," one");
break;
case 2:
strcat(cdisp," two");
break;
case 3:
strcat(cdisp," three");
break;
case 4:
strcat(cdisp," four");
break;
case 5:
strcat(cdisp," five");
break;
case 6:
strcat(cdisp," six");
break;
case 7:
strcat(cdisp," seven");
break;
case 8:
strcat(cdisp," eight" );
break;
case 9:
strcat(cdisp," nine" );
break;
}
}
irem = inum%1000;
if( irem >= 100)
{
int itemp = irem/100;
switch (itemp)
{
case 1:
strcat(cdisp," hundred");
break;
case 2:
strcat(cdisp," twohundred");
break;
case 3:
strcat(cdisp," threehundred");
break;
case 4:
strcat(cdisp," fourhundred");
break;
case 5:
strcat(cdisp," fifvehundred");
break;
case 6:
strcat(cdisp," sixhundred");
break;
case 7:
strcat(cdisp," sevenhundred");
break;
case 8:
strcat(cdisp," eighthundred" );
break;
case 9:
strcat(cdisp," ninehundred" );
break;
}
}
strcat(cdisp,"\n");
cout<<"the word is " << cdisp;
system("PAUSE");
return EXIT_SUCCESS;
}