Saturday, May 22, 2010

Kinda basic programming C++?

I need to write a program that uses pointers that will read the value of a check amount (from 00.01 to 99.99) and write out the amount in words.


EX : input into program 34.43





program outputs Thirty four and 43/100





I have no idea how to go about writing this. please help.

Kinda basic programming C++?
well, my suggestion is this: make a class.





give the class three member variables:


int dollar1, dollar2, cents





now, I think it should be easy for you to figure out from there if you know anything about classes. I've picked one variable for cent so that you can output


if(dollar1 == 1)


cout %26lt;%26lt; One


else if


(dollar1==2)


cout%26lt;%26lt; Two;


//(and so on)


cout %26lt;%26lt; ' ';


if(dollar2==1)


cout %26lt;%26lt; one;


and so on


cout %26lt;%26lt; ' ' + cents +"\\ 100 cents";
Reply:#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;string.h%26gt;


main()


{


clrscr();


float value;


int tens,units,decimal;


char outputstring[256];





cout%26lt;%26lt;"enter the value : ";


cin%26gt;%26gt; value;


decimal=(value -(float) ((int)value))*100.0;


tens=value/10;


units=value-tens*10;


strcpy(outputstring,"");


switch(tens)


{


case 2:


strcpy(outputstring,"twenty");


break;


case 3 :


strcpy(outputstring,"thirty");


break;


case 4:


strcpy(outputstring,"fourty");


break;


case 5 :


strcpy(outputstring,"fifty");


break;


case 6:


strcpy(outputstring,"sixty");


break;


case 7 :


strcpy(outputstring,"seventy");


break;


case 8:


strcpy(outputstring,"eighty");


break;


case 9 :


strcpy(outputstring,"ninety");


break;


}


switch(units)


{


case 1:


if(tens == 1)


strcat(outputstring," eleven");


else


strcat(outputstring," one");


break;


case 2:


if(tens == 1)


strcat(outputstring," twelve");


else


strcat(outputstring," two");


break;


case 3 :


if(tens == 1)


strcat(outputstring," thirteen");


else


strcat(outputstring," three");


break;


case 4:


if(tens == 1)


strcat(outputstring," fourteen");


else


strcat(outputstring," four");


break;


case 5 :


if(tens == 1)


strcat(outputstring," fifteen");


else


strcat(outputstring," five");


break;


case 6:


if(tens == 1)


strcat(outputstring," sixteen");


else


strcat(outputstring," six");


break;


case 7 :


if(tens == 1)


strcat(outputstring," seventeen");


else


strcat(outputstring," seven");


break;


case 8:


if(tens == 1)


strcat(outputstring," eighteen");


else


strcat(outputstring," eight");


break;


case 9 :


if(tens == 1)


strcat(outputstring," nineteen");


else


strcat(outputstring," nine");


break;


}





cout%26lt;%26lt; "\n ouput is : " %26lt;%26lt; outputstring %26lt;%26lt; " and"%26lt;%26lt;decimal%26lt;%26lt; "/100";





getch();


}

elephant ear

No comments:

Post a Comment