so how would i be able to write a code to 99.99
this is what i got in c++
#include <iostream>
#include <string>
using namespace std;
const static int values[] = { 90, 80, 70, 60, 50, 40, 30, 20,
19, 18, 17, 16, 15, 14, 13, 12, 11,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
const static std::string numbers[] = { "Ninety", "Eighty","Seventy", "Sixty",
"Fifty", "Forty", "Thirty", "Twenty",
"Nineteen", "Eighteen", "Seventeen",
"Sixteen", "Fifteen",
"Fourteen", "Thirteen", "Twelve",
"Eleven", "Ten", "Nine", "Eight",
"Seven", "Six", "Five", "Four", "Three",
"Two", "One" };
int main( void )
{
cout << "Enter a dollar.cents amount: ";
float amount = 0.0F;
cin >> amount;
int dollars = (int)amount;
int cents = (int)((amount - dollars) * 100.101);
int saved = dollars;
std::string answer = "";
int index = 0;
while( dollars > 0)
{
if( dollars >= values[index])
{
answer += numbers[index];
answer += " ";
dollars -= values[index];
}
++index;
}
if( saved == 0 && cents > 1 )
{
cout << saved << " dollars and " << ((cents > 0)?(cents):(0)) << " cents"
<< endl;
}
if( saved == 0 && cents == 0 )
{
cout << "Why are we writing a check for no amount?" << endl;
}
if( saved == 0 && cents == 1 )
{
cout << saved << " dollars and " << cents << " cent" << endl;
}
if( saved > 1 && cents > 1 )
{
cout << answer << "dollars and " << ((cents > 0)?(cents):(0)) << " cents"
<< endl;
}
if( saved > 1 && cents == 1 )
{
cout << answer << "dollars and " << cents << " cent" << endl;
}
if( saved > 1 && cents == 0 )
{
cout << answer << "dollars and " << 0 << " cents" << endl;
}
if( saved == 1 && cents > 1 )
{
cout << answer << "dollar and " << ((cents > 0)?(cents):(0)) << " cents"
<< endl;
}
if( saved == 1 && cents == 1 )
{
cout << answer << "dollar and " << cents << " cent" << endl;
}
return 0;
}
bout after the point it not workin corrrectly
~Rick <[EMAIL PROTECTED]> wrote:
At Friday 10/19/2007 12:09 AM, you wrote:
>this is g8t is this related to cryptography i gues then i could help as wel
No, this has nothing to do with cryptography. It
simple expresses a binary number in "written" format.
~Rick
>[EMAIL PROTECTED] wrote: even u
>can use a recursive function to do that
>
>On 10/18/07, ~Rick <[EMAIL PROTECTED]> wrote:
> >
> > At Monday 10/15/2007 03:51 PM, you wrote:
> > >so for i have this code but i dont know how ot make it say 99.99 =
> > >ninty nine point ninty nine
> > > when i input it
> > >
> > > #include<stdio.h>
> > >#include<string.h>
> > >#include<iostream.h>
> > > int digit;
> > >int main(void)
> > >{
> > >printf("Please enter a number between 0 and 99.99: \n");
> > > scanf("%d");
> > > switch(digit)
> > > {
> > > case 0: printf("Zero");
> > > break;
> > > case 1: printf("One");
> > > break;
> > > case 2: printf("Two");
> > > break;
> > > case 3: printf("Three");
> > > break;
> > > case 4:printf("Four");
> > > break;
> > > case 5:printf("Five");
> > > break;
> > > case 6:printf("Six");
> > > break;
> > > case 7:printf("Seven");
> > > break;
> > > case 8:printf("Eight");
> > > break;
> > > case 9:printf("Nine");
> > > break;
> > > case 11:printf("Ten");
> > > break;
> > > case 12:printf("Three");
> > > break;
> > > default: printf("Just a Test");
> > > printf("%d \n", digit);
> > > }
> > >}
> > >
> >
> > Okay, for fun I wrote the program. It will work for numbers up to
> > 1999999999.1999999999.
> > I used two output methods; one to print just the "numbers" (e.g. nine
> > nine point nine nine) and another to print the actual "words" (e.g.
> > ninety-nine point ninety-nine).
> > As a test, I used the first method for numbers to the left of the
> > decimal, and the second for numbers to the right of the decimal.
> >
> > Here is a sample output:
> >
> > Your number was 99.99
> > NINETY-NINE POINT NINE NINE
> >
> > Your number was 519625.9823
> > FIVE HUNDRED NINETEEN THOUSAND SIX HUNDRED TWENTY-FIVE POINT NINE
> > EIGHT TWO THREE
> >
> > Your number was 1234567890.987654321
> > ONE BILLION TWO HUNDRED THIRTY-FOUR MILLION FIVE HUNDRED SIXTY-SEVEN
> > THOUSAND EIGHT HUNDRED NINETY POINT NINE EIGHT SEVEN SIX FIVE FOUR
> > THREE TWO ONE
> >
> > Your number was 2007.10
> > TWO THOUSAND SEVEN POINT ONE ZERO
> >
> > The "numbers" code is quite simple, You will need to do a lot more
> > checking to implement the "words" code, like check the previous digit
> > (and decimal position) to accommodate "teens" and "*ty-" numbers.
> >
> > Is this what you are trying to do?
> >
> > ~Rick
> >
> >
> >
>
>--
>(¨`·.·´¨)
>`·.¸(¨`·.·´¨) Keep
>(¨`·.·´¨)¸.·´ Smiling!
>`·.¸.·´ S H I S H I R S H A R M A 'Criss'
>----------------------------------------------------------
>"Don't Quit"
>
>...and whats life without an impossible dream...
>----------------------------------------------------------
>[EMAIL PROTECTED]
>
>[Non-text portions of this message have been removed]
>
>
>
>
>
>
>---------------------------------
> Now you can chat without downloading messenger. Click here to know how.
>
>[Non-text portions of this message have been removed]
>
>
>
>To unsubscribe, send a blank message to
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
[Non-text portions of this message have been removed]