switch and things

help regarding our assignment

the trick is input a number -999 to 999

we cant use == ,

i cant simply make this work, what i have in mind is separate hundreds and tens, one and use it for switch

thank you!

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
#include <stdio.h>

int number, hundred, ten, tenmod, one; 
			
int main(void){
	
	puts("please enter a number from -999 to 999:");
	scanf("%d", &number);
	
	hundred = number / 100;
	ten = number % 100;
	tenmod = ten / 10;
	one = ten % 10;
	
	printf("%d%d%d", hundred, ten, one);
	
		switch(hundred){
                   case 9 : printf("\nNine Hundred\n");
                   break;
                   case 8 : printf("\nEight Hundred\n");
                   break;
                   case '7' : printf("\nSeven Hundred\n");
                   break;
                   case '6' : printf("\nSix Hundred\n");
                   break;
                   case '5' : printf("\nFive Hundred\n");
                   break;
                   case '4' : printf("\nFour Hundred\n");
                   break;
                   case '3' : printf("\nThree Hundred\n");
                   break;
                   case '2' : printf("\nTwo Hundred\n");
                   break;
                   case '1' : printf("\nOne Hundred\n");
                   break;
                   case '-9' : printf("\nNegativeNine Hundred\n");
                   break;
                   case '-8' : printf("\nNegativeEight Hundred\n");
                   break;
                   case '-7' : printf("\nNegative Seven Hundred\n");
                   break;
                   case '-6' : printf("\nNegative Six Hundred\n");
                   break;
                   case '-5' : printf("\nNegativeFive Hundred\n");
                   break;
                   case '-4' : printf("\nNegative Four Hundred\n");
                   break;
                   case '-3' : printf("\nNegative Three Hundred\n");
                   break;
                   case '-2' : printf("\nNegative Two Hundred\n");
                   break;
                   case '-1' : printf("\nNegative One Hundred\n");
                   break;
				   }  
            
		switch(tenmod){
			 
                   case '9' : printf("\nNinety\n");
                   break;
                   case '8' : printf("\nEighty\n");
                   break;
                   case '7' : printf("\nSeventy\n");
                   break;
                   case '6' : printf("\nSixty\n");
                   break;
                   case '5' : printf("\nFifty\n");
                   break;
                   case '4' : printf("\nForty\n");
                   break;
                   case '3' : printf("\nThirty\n");
                   break;
                   case '2' : printf("\nTwenty\n");
                   break;
                   case '11' : printf("\nEleven\n");
                   break;
                   case '12' : printf("\nTwelve\n");
                   break;
                   case '13' : printf("\nThrirteen\n");
                   break;
                   case '14' : printf("\nFourtheen\n");
                   break;
                   case '15' : printf("\nFifteen\n");
                   break;
                   case '16' : printf("\nSixteen\n");
                   break;
                   case '17' : printf("\nSeventeen\n");
                   break;
                   case '18' : printf("\nEighteen\n");
                   break;
                   case '19' : printf("\nNineteen\n");
				   } 
			
			switch(one){
			 
                   case '9' : printf("\nNine\n");
                   break;
                   case '8' : printf("\nEight\n");
                   break;
                   case '7' : printf("\nSeven\n");
                   break;
                   case '6' : printf("\nSix\n");
                   break;
                   case '5' : printf("\nFive\n");
                   break;
                   case '4' : printf("\nFour\n");
                   break;
                   case '3' : printf("\nThree\n");
                   break;
                   case '2' : printf("\nTwo\n");
                   break;
				   } 
	*/
	system("pause");
	return 0;
}

Missing header file: Windows.h for "system" (BTW it's a bad habit to get into)

You have quotes on some cases, but not all. Why? You don't even need to put quotes on them actually.

Line 15 you pass ten instead of tenmod as a parameter, thus the incorrect output there.

Your ten's and one's place switch statement, you skip both case 1. Why? How will you print 10? Or 1? You gave the hundred's place switch statement a case 1.
Last edited on
i want to separate the elevens to nineteen,, sorry i might just missed typing it

from ex. fifty one, etc.
Last edited on
You see, that's where it gets complicated. All of the "teen" numbers are made up of two places: a tens and ones place. You're going to have to check whether the tens place is equal to one or not to decide when you add the "teen" suffix to the number. I.E. 127 doesn't get the suffix, but 117 will.
yeah thats the problem,
Missing header file: Windows.h for "system"
Since when system had moved from <cstdlib> to windows.h?
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>

 //enter number , -999 to 999
			// no ==
			//BCS111, VELEZ, LE#3 , decamora.lawrence@ciit-ph.com
			
int main(void){
	
	int number, hundred, tens, tenss, tenmod, one, x;
	
	puts("please enter a number from -999 to 999:");
	scanf("%d", &number);
	
	hundred = number / 100;
 
	
		switch(hundred){
                   case 9 : printf("\nNine Hundred");
                   break;
                   case 8 : printf("\nEight Hundred");
                   break;
                   case 7 : printf("\nSeven Hundred");
                   break;
                   case 6 : printf("\nSix Hundred");
                   break;
                   case 5 : printf("\nFive Hundred");
                   break;
                   case 4 : printf("\nFour Hundred");
                   break;
                   case 3 : printf("\nThree Hundred");
                   break;
                   case 2 : printf("\nTwo Hundred");
                   break;
                   case 1 : printf("\nOne Hundred");
                   break;
                   case -9 : printf("\nNegative Nine Hundred");
                   break;
                   case -8 : printf("\nNegative Eight Hundred");
                   break;
                   case -7 : printf("\nNegative Seven Hundred");
                   break;
                   case -6 : printf("\nNegative Six Hundred");
                   break;
                   case -5 : printf("\nNegativeFive Hundred");
                   break;
                   case -4 : printf("\nNegative Four Hundred");
                   break;
                   case -3 : printf("\nNegative Three Hundred");
                   break;
                   case -2 : printf("\nNegative Two Hundred");
                   break;
                   case -1 : printf("\nNegative One Hundred");
                   break;
				   }  
				   
             // if ( x < 10 && x > 20){    
                      	
                   x = number % 100;
				  
               if ( x > 10 && x < 20){   
                 
                   switch(x){ 
                   case 11 : printf(" Eleven");
                   break;
                   case 12 : printf(" Twelve");
                   break;
                   case 13 : printf(" Thirteen");
                   break;
                   case 14 : printf(" Fourteen");
                   break;
                   case 15 : printf(" Fifteen");
                   break;
                   case 16 : printf(" Sixteen");
                   break;
                   case 17 : printf(" Seventeen");
                   break;
                   case 18 : printf(" Eighteen");
                   break;
                   case 19 : printf(" Nineteen");
                   break;
                   } 
                   }
               else if (tens > -10 && tens < 10){ 
                   
                   
                   tens = (number % 100) / 10;
 
                   switch(tens){
			 	   case -9 :
                   case 9 : printf(" Ninety ");
                   break;
                   case -8 :
                   case 8 : printf(" Eighty ");
                   break;
                   case -7 :
                   case 7 : printf(" Seventy ");
                   break;
                   case -6 :
                   case 6 : printf(" Sixty ");
                   break;
                   case -5 :
                   case 5 : printf(" Fifty ");
                   break;
                   case -4 :
                   case 4 : printf(" Forty ");
                   break;
                   case -3 :
                   case 3 : printf(" Thirty ");
                   break;
                   case -2 :
                   case 2 : printf(" Twenty ");
                   break;
                   case -1 :
                   case 1 : printf(" Ten ");
                   break;               
				   } 
} 
//if (one > -10 && one <10) {

                            one = x % 10;             
       
		                	switch(one){
                            case -9 :
                            case 9 : printf(" Nine\n");
                            break;
                            case -8 :
                            case 8 : printf(" Eight\n");
                            break;
                            case -7 :
                            case 7 : printf(" Seven\n");
                            break;
                            case -6 :
                            case 6 : printf(" Six\n");
                            break;
                            case -5 :
                            case 5 : printf(" Five\n");
                            break;
                            case -4 :
                            case 4 : printf(" Four\n");
                            break;
                            case -3 :
                            case 3 : printf(" Three\n");
                            break;
                            case -2 :
                            case 2 : printf(" Two\n");
                            break;
                            case -1 :
                            case 1 : printf(" One\n");
                            break;
				            }   
                           // }
       
                
	system("pause");
	return 0;
}


need help what to do to correct this?

it show 911 = nine hundred eleven one, other numbers works flawlessly, how can i say to stop once it selected eleven to nineteen
In these special cases, try using return instead of break
where would i put the break? it closes automatically if i change the breaks to return in line 63
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <stdio.h>

void read_number(int n)
{
    int number = n, hundred, tens, tenss, tenmod, one, x;

    hundred = number / 100;

    switch(hundred) {
    case 9 :
        printf("\nNine Hundred");
        break;
    case 8 :
        printf("\nEight Hundred");
        break;
    case 7 :
        printf("\nSeven Hundred");
        break;
    case 6 :
        printf("\nSix Hundred");
        break;
    case 5 :
        printf("\nFive Hundred");
        break;
    case 4 :
        printf("\nFour Hundred");
        break;
    case 3 :
        printf("\nThree Hundred");
        break;
    case 2 :
        printf("\nTwo Hundred");
        break;
    case 1 :
        printf("\nOne Hundred");
        break;
    case -9 :
        printf("\nNegative Nine Hundred");
        break;
    case -8 :
        printf("\nNegative Eight Hundred");
        break;
    case -7 :
        printf("\nNegative Seven Hundred");
        break;
    case -6 :
        printf("\nNegative Six Hundred");
        break;
    case -5 :
        printf("\nNegativeFive Hundred");
        break;
    case -4 :
        printf("\nNegative Four Hundred");
        break;
    case -3 :
        printf("\nNegative Three Hundred");
        break;
    case -2 :
        printf("\nNegative Two Hundred");
        break;
    case -1 :
        printf("\nNegative One Hundred");
        break;
    }

    x = number % 100;

    if ( x > 10 && x < 20) {

        switch(x) {
        case 11 :
            printf(" Eleven");
            return; //break;
        case 12 :
            printf(" Twelve");
            return; //break;
        case 13 :
            printf(" Thirteen");
            return; //break;
        case 14 :
            printf(" Fourteen");
            return; //break;
        case 15 :
            printf(" Fifteen");
            return; //break;
        case 16 :
            printf(" Sixteen");
            return; //break;
        case 17 :
            printf(" Seventeen");
            return; //break;
        case 18 :
            printf(" Eighteen");
            return; //break;
        case 19 :
            printf(" Nineteen");
            return; //break;
        }
    } else if (tens > -10 && tens < 10) {


        tens = (number % 100) / 10;

        switch(tens) {
        case -9 :
        case 9 :
            printf(" Ninety ");
            break;
        case -8 :
        case 8 :
            printf(" Eighty ");
            break;
        case -7 :
        case 7 :
            printf(" Seventy ");
            break;
        case -6 :
        case 6 :
            printf(" Sixty ");
            break;
        case -5 :
        case 5 :
            printf(" Fifty ");
            break;
        case -4 :
        case 4 :
            printf(" Forty ");
            break;
        case -3 :
        case 3 :
            printf(" Thirty ");
            break;
        case -2 :
        case 2 :
            printf(" Twenty ");
            break;
        case -1 :
        case 1 :
            printf(" Ten ");
            break;
        }
    }

    one = x % 10;

    switch(one) {
    case -9 :
    case 9 :
        printf(" Nine\n");
        break;
    case -8 :
    case 8 :
        printf(" Eight\n");
        break;
    case -7 :
    case 7 :
        printf(" Seven\n");
        break;
    case -6 :
    case 6 :
        printf(" Six\n");
        break;
    case -5 :
    case 5 :
        printf(" Five\n");
        break;
    case -4 :
    case 4 :
        printf(" Four\n");
        break;
    case -3 :
    case 3 :
        printf(" Three\n");
        break;
    case -2 :
    case 2 :
        printf(" Two\n");
        break;
    case -1 :
    case 1 :
        printf(" One\n");
        break;
    }
}

int main(void)
{
    for(int i = 0; i <= 100; ++i) {
        read_number(i);
    }

    return 0;
}
thanks man! what does putting return do there? it returns it to the top or stops it? incase i'm asked what about it?
Look for c++ Interpreter Design Pattern , it could help.

Missing header file: Windows.h for "system"
Since when system had moved from <cstdlib> to windows.h?


Including window.h lets you access system. Try it out.
Including window.h lets you access system
It lets you to do this on your concrete version of windows.h. Correct header to include is stdlib.h/cstdlib. windows.h might include one of those, this is why name system becomes visible for you.
Still windows.h is not reqiured to do so, and might stop behaving same way later/earlier. Name system() does appears anywhere in official documentation for windows.h, therefore assuming that it will bring it is a bad idea.
C++ stanard says that you should include <cstdio> for system, period. Relying on side effect of implementation is never appropriate.
Last edited on
Thank you for the clarification.
Topic archived. No new replies allowed.