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