View Single Post
Old 10-20-2004, 02:44 PM   #5 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Run this and enter:
1.02

Can you finish it? :)
Code:
 #include <iostream>
#include <string>
#include <climits>
#include <cmath>


using namespace std;

//Optional function: depends on IDE. void wait_for_enter();

//Additional helper. void reset_istream();

//The model.
string Words[]={"null" ,"one", "two"};

int main(int argc, char *argv[])
{
   double theAmount;
   
   cout<<"Enter the amount please:"<<endl<<"-> ";
   cin>>theAmount;
   
   double theDollars;
   double theCents;
   theCents=modf(theAmount, &theDollars)*100;
   
   cout<<theDollars<<" "<<theCents<<endl;
   
   cout<<Words[(unsigned)theDollars]<<" : "<<Words[(unsigned)theCents]<<endl;

   reset_istream();
   wait_for_enter();
   return 0;
}

//--------------------------------------------------- void reset_istream()
{
   if(cin.eof())
   {
      cin.clear();
   }
   else
   {
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(), '\n');
   }
}

//--------------------------------------------------- void wait_for_enter()
{
  cout << "press <enter> to continue...";
  // Reset failstate, just in case.
  cin.clear();
  string line;
  getline( cin, line);
}
The cool thing about this is that you can do it in a million ways. See if you like to study std::map and std::pair.
__________________
Valmont is offline   Reply With Quote