printWords should look like:
* convert hundreds
* convert tens
* convert units
Hundreds is easy: it returns: one, two, three, ..., nine.
Tens have to deal with the special cases of:
* nothing for numbers less than 10.
* eleven, twelve, thirteen, ..., nineteen for 11-19
* ten, twenty, thirty, ..., ninety otherwise
Units are:
* one, two, three, ..., nine where the tens is not 11-19
* nothing otherwise
Please do not remove your posts after you got an answer.
Original posts:
so this is my question.>>
Write program that uses a function digit that generates a random number
between 100 and 999 and calls a function printWords print it out digit by digit, as a series of words.
and this is the output.>>
Sample run:
The number is 523, in other word five two three
and this is my code!!!
and i need help to complete it and see if the order is right??
Since the current code is not calling digit() and printword(), lets get this down to something which is just your main(). Let's see if we can get the basic structure working with simulations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
#define n 123
#define PrintWords(n) "One hundred Twenty Three"
int main()
{
cout << n << " in words: " << PrintWords(n);
return 0;
}
Now, what do you think you next steps are? Do one step at a time; test after each step.
#include <iostream>
usingnamespace std;
#include <cstdlib>
#include <ctime>
usingnamespace std;
int digit()
{
int num;
int count = 1;
unsigned seed = time(0);
srand(seed);
while(count <= 1)
{
num = 100 + rand() % 899;
cout <<"the number is: "<< num <<" ,\t";
count++;
}
return num;
}
void printwords(int num)
{
int n;
int m;
n = num/100;
m = num%100;
for (int i=1; i <=3 ;i++)
{
switch (n)
{
case 0:
cout<< "zero \t'";
break;
case 1:
cout<< "one \t";
break;
case 2:
cout<< "two \t";
break;
case 3:
cout<< "three \t";
break;
case 4:
cout<< "four \t";
break;
case 5:
cout<< "five \t";
break;
case 6:
cout<< "six \t";
break;
case 7:
cout<< " seven \t";
break;
case 8:
cout<< " eight \t";
break;
case 9:
cout<< " nine \t";
break;
}
if (m > 10)
{ n = m /10;
m%=10;
}
else
n = m;
}
}
int main()
{
int d = digit();
cout << "in other words: " ;
printwords(d);;
return 0;
}
/*
the number is: 882 , in other words: eight eight two Press any key to
continue
*/
/*
the number is: 996 , in other words: nine nine six Press any key to
continue
*/