question went to another post

i moved the question to another post with the same code...
Last edited on
question is sent to another post.. with the same code unchanged..
Last edited on
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

It's a bit tricky.
Last edited on
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??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>

using namespace std;


#include <cstdlib>
#include <ctime>

using namespace std;

int digit()
{
int num;
int count = 1;
unsigned seed = time(0);

srand(seed);

while(count <= 1)
{
num = 100 + rand() % 899;
cout << num << endl;
count++;
}

return num;
}


char printwords()
{
	switch (num)

	{
	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;

	}

}  
already did some of it but i need help to complete it.. and thanks


Last edited on
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>

using namespace 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.
Last edited on
pheininger



thanks a lot i appreciate ..
i`ll try and post my resulted code later!! :)
here is the solution code for the question!!

thanks to whom helped...sorry for being late!!!



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>

using namespace std;


#include <cstdlib>
#include <ctime>

using namespace 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
 */
Please don't use switch for something like this, it's a waste of processing time and giant amount of unnecessary text.

Just make a array of words and access them by index...

1
2
char day[10] = {"zero", "one", ....};
cout << day[n];
yeah i know ... but we didn`t learn that yet!! i`m still a beginner !!:s
zoran404
Topic archived. No new replies allowed.