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??
#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;
}
char printwords()
{
int n;
n = num/10;
n = n%10;
if (n <10)
{
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;
}
}
else
{
return n=n%10;
}
return n;
}
int main()
{
cout << "in other words: " << n;
return 0;
}
i thank yew alot for you work ,, but can`t it be with the use of switch?? as it`s my extra class and we still didn`t get to the level you reached in programing...
i`ll be so thankful for yew if you can explain why not using switch or 2 functions other than main .. and if posiible with my junior way,,, how is it possible to make it right????
:-) I wasn't actually trying to solve it for you, I was hoping you'd look for clues in my program.
Also, the stuff in main is just for testing the function.
You could use your switch for printing out number values (i used map), and , you could first determine the number of digits in the number, then create an array of the same size as that number of digits, then extract each digit starting from the lowest, but storing them in your array, then finally print out all members of the array in reverse order (i used vector)
#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
*/