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
Brett McCoy <[EMAIL PROTECTED]> wrote: On 10/23/07, mano M <[EMAIL
PROTECTED]> wrote:
> I have a C program that reads from stdin and process some calculation. I need
> to write another sample program that send the data into stdin . My Cprogram
> should read this data from stdin. This should work like sequential job(1
> program send the data to stdin and 2nd program reads data from stdin and
> process) This is a part of simulation of a job. I have the 2nd program .How
> can I simulate it. How can I execute it.(is it possible using pipe)
Yes, using a pipe on the command-line is the canonical way of doing this.
prog1 | prog2
Just about any OS with a command-line supports this. What's the problem?
-- Brett
----------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi
__________________________________________________
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]