Expected unqualified - id ERROR

I'm programming a 99 bottles of beer on the wall program and I have one error reading "Expected unqualified -id" on it... I can't figure out why it's there.

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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
 //  Created by LeeeeJ on 3/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <string>

using namespace std; 

string int2word(int);
string tens(int); 
string teens(int);
string ones(int); 



// for loop to count down

int main () 
{ 
    int bottles = 99; 
    
    for (int i=99; i > 0; i --){
    
    cout << int2word(i) << " bottles of beer on the wall!" << endl; 
    cout << int2word(i) << " bottles of beer!" << endl; 
    cout << "Take one down and pass it around " << endl; 
    cout << int2word(i-1) << " bottles of beer on the wall!" << endl << endl; 

    }
    return 0; 

  

}

// I keep getting an error in this next line of cone and it says "Expected unqualified -id." 
// My teens string isn't running because of this next line of code. 
//I want to making some sort of statement saying "if not - 20, 
 
// The error occurs right underneath
if !(num <= 19 && num > 0)
ret = tens(num/10) + "-" + ones(num%10)
        return ret;


      

    string int2word(int num)
{
    string ret; 
}  



    string tens(int num)
{
    
    string ret; 
    switch (num) {
        case 9:
            ret = "Ninety";
            break; 
         
            ret = "ERROR"; 
            break; 

        case 8:
            ret = "Eighty";
            break; 
            
            ret = "ERROR"; 
            break;         
    
        case 7:
            ret = "Seventy";
            break; 
      
            ret = "ERROR"; 
            break;       
      
        case 6: 
            ret = "Sixty"; 
            break; 
        
            ret = "ERROR"; 
            break; 
            
        case 5: 
            ret = "Fifty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
            
            
        case 4: 
            ret = "Fourty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
            
            
        case 3: 
            ret = "Thirty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
            
        case 2: 
            ret = "Twenty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
    }
            
    return ret;
}

string teens(int num)
{
    string ret; 
    switch (num) {
        case 19:
            ret = "Nineteen";
            break; 
            
            ret = "ERROR"; 
            break;  
        
        case 18:
            ret = "eighteen";
            break; 
            
            ret = "ERROR"; 
            break;   
        
        case 17:
            ret = "Seventeen";
            break; 
            
            ret = "ERROR"; 
            break;       
        
        case 16:
            ret = "Sixteen";
            break; 
            
            ret = "ERROR"; 
            break;  
        
        case 15:
            ret = "Fifteen";
            break; 
            
            ret = "ERROR"; 
            break;   
        
        case 14:
            ret = "Fourteen";
            break; 
            
            ret = "ERROR"; 
            break;    
        
        case 13:
            ret = "Thirteen";
            break; 
            
            ret = "ERROR"; 
            break;
        
        case 12:
            ret = "Twelve";
            break; 
            
            ret = "ERROR"; 
            break;  
        
        case 11:
            ret = "Eleven";
            break; 
            
            ret = "ERROR"; 
            break; 
        
        case 10:
            ret = "Ten";
            break; 
            
            ret = "ERROR"; 
            break;        
    }
    
} 
  
    string ones(int num)
{
    string ret;
    switch (num){
        case 9:
            ret="Nine";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 8:
            ret="Eight";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 7:
            ret="Seven";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 6:
            ret="Six";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 5:
            ret="Five";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 4:
            ret="Four";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 3:
            ret="Three";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 2:
            ret="Two";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 1:
            ret="One";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 0:
            ret="";
        break;}
    return ret;

}


   
//if statement, another function called teens 
Last edited on
The reason it isn't working is because you have an if statement just sitting there in the global scope, it needs to be in a function somewhere.

It looks like it should be in your 'int2word' function, so change it to something like this.
1
2
3
4
5
6
7
8
9
10
11
12
string int2word(int num)
{
	string ret; 

	if (!(num <= 19 && num > 0))
	{
		ret = tens(num/10) + "-" + ones(num%10);
		return ret;
	}

	//Needs check for rest of numbers
}  


The second problem is you can't follow an if statement directly with a !. You need to include another set of () if you want to check the variables inside of it (as added in the code above).

Also don't forget your teens function is meant to be returning a string, but it isn't returning anything right now.
Great! Thanks for the help, I appreciate it!
I can't seem to print 19-10 bottles of beer on the wall though! Any suggestions?

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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

#include <iostream>
#include <string>

using namespace std; 

string int2word(int);
string tens(int); 
string teens(int);
string ones(int); 



// for loop to count down

int main () 
{ 
    
    for (int i=99; i > 0; i --){
    
    cout << int2word(i) << " bottle(s) of beer on the wall!" << endl; 
    cout << int2word(i) << " bottle(s) of beer!" << endl; 
    cout << "Take one down and pass it around " << endl; 
    cout << int2word(i-1) << " bottle(s) of beer on the wall!" << endl << endl; 

    }
    return 0; 

  

}

// I keep getting an error in this next line of cone and it says "Expected unqualified -id." 
// My teens string isn't running because of this next line of code. 
//I want to making some sort of statement saying "if not - 20, 
 
string int2word(int num)
{
	string ret; 
    
	if (!(num <= 19 && num > 0))
	{
		ret = tens(num/10) + "-" + ones(num%10);
		return ret;
	
    
	//Needs check for rest of numbers

    
}  



    string tens(int num);
{
    
    string ret; 
    switch (num) {
        case 9:
            ret = "Ninety";
            break; 
         
            ret = "ERROR"; 
            break; 

        case 8:
            ret = "Eighty";
            break; 
            
            ret = "ERROR"; 
            break;         
    
        case 7:
            ret = "Seventy";
            break; 
      
            ret = "ERROR"; 
            break;       
      
        case 6: 
            ret = "Sixty"; 
            break; 
        
            ret = "ERROR"; 
            break; 
            
        case 5: 
            ret = "Fifty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
            
            
        case 4: 
            ret = "Fourty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
            
            
        case 3: 
            ret = "Thirty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
            
        case 2: 
            ret = "Twenty"; 
            break; 
            
            ret = "ERROR"; 
            break; 
    }
            
    return ret;
}

    string teens(int num);
{
    string ret; 
    switch (num) {
        case 19:
            ret = "Nineteen";
            break; 
            
            ret = "ERROR"; 
            break;  
        
        case 18:
            ret = "eighteen";
            break; 
            
            ret = "ERROR"; 
            break;   
        
        case 17:
            ret = "Seventeen";
            break; 
            
            ret = "ERROR"; 
            break;       
        
        case 16:
            ret = "Sixteen";
            break; 
            
            ret = "ERROR"; 
            break;  
        
        case 15:
            ret = "Fifteen";
            break; 
            
            ret = "ERROR"; 
            break;   
        
        case 14:
            ret = "Fourteen";
            break; 
            
            ret = "ERROR"; 
            break;    
        
        case 13:
            ret = "Thirteen";
            break; 
            
            ret = "ERROR"; 
            break;
        
        case 12:
            ret = "Twelve";
            break; 
            
            ret = "ERROR"; 
            break;  
        
        case 11:
            ret = "Eleven";
            break; 
            
            ret = "ERROR"; 
            break; 
        
        case 10:
            ret = "Ten";
            break; 
            
            ret = "ERROR"; 
            break;        
    }
    
} 
  
    string ones(int num);
{
    string ret;
    switch (num){
        case 9:
            ret="Nine";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 8:
            ret="Eight";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 7:
            ret="Seven";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 6:
            ret="Six";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 5:
            ret="Five";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 4:
            ret="Four";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 3:
            ret="Three";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 2:
            ret="Two";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 1:
            ret="One";
            break;
            
            ret = "ERROR"; 
            break; 
        
        case 0:
            ret="";
        break;}
    return ret;

}

    
   
//if statement, another function called teens




Twenty-One bottles of beer on the wall
Twenty-One bottles of beer
Take one down and pass it around 
Twenty- bottles of beer on the wall!

Twenty- bottles of beer on the wall
Twenty- bottles of beer
Take one down and pass it around 
-Nine bottles of beer on the wall!

-Nine bottles of beer on the wall
-Nine bottles of beer
Take one down and pass it around 
-Eight bottles of beer on the wall!

-Eight bottles of beer on the wall
-Eight bottles of beer
Take one down and pass it around 
-Seven bottles of beer on the wall!

-Seven bottles of beer on the wall
-Seven bottles of beer
Take one down and pass it around 
-Six bottles of beer on the wall!

-Six bottles of beer on the wall
-Six bottles of beer
Take one down and pass it around 
-Five bottles of beer on the wall!

-Five bottles of beer on the wall
-Five bottles of beer
Take one down and pass it around 
-Four bottles of beer on the wall!

-Four bottles of beer on the wall
-Four bottles of beer
Take one down and pass it around 
-Three bottles of beer on the wall!

-Three bottles of beer on the wall
-Three bottles of beer
Take one down and pass it around 
-Two bottles of beer on the wall!

-Two bottles of beer on the wall
-Two bottles of beer
Take one down and pass it around 
-One bottles of beer on the wall!

-One bottles of beer on the wall
-One bottles of beer
Take one down and pass it around 
- bottles of beer on the wall!

- bottles of beer on the wall
- bottles of beer
Take one down and pass it around 
-Nine bottles of beer on the wall!

-Nine bottles of beer on the wall
-Nine bottles of beer
Take one down and pass it around 
-Eight bottles of beer on the wall!

-Eight bottles of beer on the wall
-Eight bottles of beer
Take one down and pass it around 
-Seven bottles of beer on the wall!

-Seven bottles of beer on the wall
-Seven bottles of beer
Take one down and pass it around 
-Six bottles of beer on the wall!

-Six bottles of beer on the wall
-Six bottles of beer
Take one down and pass it around 
-Five bottles of beer on the wall!

-Five bottles of beer on the wall
-Five bottles of beer
Take one down and pass it around 
-Four bottles of beer on the wall!

-Four bottles of beer on the wall
-Four bottles of beer
Take one down and pass it around 
-Three bottles of beer on the wall!
You need to change the function it calls depending on the number.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
string int2word(int num)
{
	string ret; 
    
	if (!(num <= 19 && num > 0))
	{
		ret = tens(num/10) + "-" + ones(num%10);
		return ret;
	}

	if (!(num <= 9 && num > 0))
	{
		ret = teens(num);
		return ret;
	}
	
	else
	{
		ret = ones(num);
		return ret;
	}
}  


Also on the code above the function names shouldn't have ; on them (which seem to have been added) and your teens function still needs to return a value.

Hopefully that makes some sense.
Topic archived. No new replies allowed.