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.