Control Structure Errors

I have to create a program where you have 4 choices and it gives you different messages. I can't compile the program due to the error messages. I can't figure out what the problems are. I know I have done program functions before...so I don't understand the erros in the void part. Maybe I called the prototypes wrong?

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
  
// Headers and Other Technical Items

#include <iostream>
using namespace std;
#include "C:\\Dev-Cpp\\user_library\\udst_monitor.h"

// Function Prototypes

void counting_loop(void);
void impossible(void);
void missing_item(void);
void odd_even(void);
void poem (void); 

// Variables

char      user_choice;
int       user_integer; 
int       x;

//******************************************************
// main
//******************************************************

int main(void)
  {
  
  do
  {
    cout << "Welcome to the Fun Program.";  
    cout << "Select from the menu."; 
    cout << "\n"; 
    cout << "A gets Counting Loop.";
    cout << "B gets Impossible."; 
    cout << "C gets Missing Item."; 
    cout << "D gets Odd or Even."; 
    cout << "E gets Poem."; 
    cout << "\n"; 
    cout << "Q quits the program."; 
    cout << "\n"; 
    cout << "Enter the letter of your choice."; 
    cout << "Then hit the enter key."; 
    cout << "\n"; 
    cout << "\nYour choice: --> "; 
    cin >> user_choice;
    
    clear_m();
    
    //case
    switch (user_choice)
    {
    case 'A': counting_loop();
         break;
    case 'B': impossible();
         break;
    case 'C': missing_item();
         break; 
    case 'D': odd_even();
         break;
    case 'E': 
         break; poem(); 
    }
    //endcase
    
    }
while (user_choice != 'Q'); 
  
  
 //******************************************************
// counting_loop
//******************************************************

void counting_loop(void) //error expected primary-expression before 'void' & expected `;' before "void" 
  {
 
 for(x = 0, x < 5; x++)
    {
    cout << "Are we having fun?"; 
    }
  return;   
  pause_m();  
  
  }

//******************************************************
// impossible
//******************************************************

void impossibe(void) //error expected primary-expression before 'void' & expected `;' before "void" 
  {
  
  cout <<"The repeat until loop is impossible in C++."; 
 
  return; 
  pause_m(); 
  
  )
//******************************************************
// missing_item
//******************************************************

void missing_item(void)
  {
  
  cout << "This program is missing only the while loop"; 
  
  return; 
  pause_m(); 
  
  }


//******************************************************
// odd_even
//******************************************************

void odd_even(void)
  {
  
  cout << "\nEnter a whole number only."; 
  cin >> user_integer; 
  
  If (user_integer modulus 2) 
  {
  cout <<"\nYour numnber was odd."; 
  }
  else
  {
  cout <<"\nYour number was even."; 
  }
  
  return; 
  pause_m(); 
  
  }

//******************************************************
// poem
//******************************************************

void poem(void)
  {
  
  cout << "Blow, blow, thou winter wind,"; 
  cout << "Thou art not so unkind"; 
  cout << "As man's ingratitude"; 
  cout << "Thy tooth is not so keen"; 
  
  
  return;
  pause_m();
   
  
  ) //error  expected `}' at end of input 

//******************************************************
// End of Program
//******************************************************

Last edited on
Just a few things

You never closed out int main with return 0;

() these are not the same as {} line 98 and 155 for example
Oh, great. I didn't see those errors....I changed my code and now I'm getting new errors

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

// Headers and Other Technical Items

#include <iostream>
using namespace std;
#include "C:\\Dev-Cpp\\user_library\\udst_monitor.h"

// Function Prototypes

void counting_loop(void);
void impossible(void);
void missing_item(void);
void odd_even(void);
void poem (void); 

// Variables

char      user_choice;
int       user_integer; 
int       x;

//******************************************************
// main
//******************************************************

int main(void)
  {
  
  do
  {
    cout << "Welcome to the Fun Program.";  
    cout << "Select from the menu."; 
    cout << "\n"; 
    cout << "A gets Counting Loop.";
    cout << "B gets Impossible."; 
    cout << "C gets Missing Item."; 
    cout << "D gets Odd or Even."; 
    cout << "E gets Poem."; 
    cout << "\n"; 
    cout << "Q quits the program."; 
    cout << "\n"; 
    cout << "Enter the letter of your choice."; 
    cout << "Then hit the enter key."; 
    cout << "\n"; 
    cout << "\nYour choice: --> "; 
    cin >> user_choice;
    
    clear_m();
    
    //case
    switch (user_choice)
    {
    case 'A': counting_loop();
         break;
    case 'B': impossible();
         break;
    case 'C': missing_item();
         break; 
    case 'D': odd_even();
         break;
    case 'E': 
         break; poem(); 
    }
    //endcase
    
    }
while (user_choice != 'Q'); 

    return 0;
    }
  
  
 //******************************************************
// counting_loop
//******************************************************

void counting_loop(void) 
  {
 
 for(x = 0; x < 5; x++)    
 {
    cout << "Are we having fun?"; 
    }
  
  return;   
  pause_m();  
  
  }
  
  //errors in this area 
  //Pseudocode says: 
  //Function counting_loop 
  //Pass In: nothing 
  //For x starts at 0, x < 5, increment x 
  //Display "Are we having fun?"
  //Endfor
  //Call: pause_m
  //Pass Out: nothing
  //Endfuction

//******************************************************
// impossible
//******************************************************

void impossibe(void) 
  {
  
  cout <<"The repeat until loop is impossible in C++."; 
 
  return; 
  pause_m(); 
  
  }
//******************************************************
// missing_item
//******************************************************

void missing_item(void)
  {
  
  cout << "This program is missing only the while loop"; 
  
  return; 
  pause_m(); 
  
  }


//******************************************************
// odd_even
//******************************************************

void odd_even(void)
  {
  
  cout << "\nEnter a whole number only."; 
  cin >> user_integer; 
  
  If (user_integer modulus 2) //error here pseudocode for this says: If user_integer modulus 2
  {
  cout <<"\nYour numnber was odd."; 
  }
  else
  {
  cout <<"\nYour number was even."; 
  }
  
  return; 
  pause_m(); 
  
  }

//******************************************************
// poem
//******************************************************

void poem(void)
  {
  
  cout << "Blow, blow, thou winter wind,"; 
  cout << "Thou art not so unkind"; 
  cout << "As man's ingratitude"; 
  cout << "Thy tooth is not so keen"; 
  
  
  return; 
  pause_m();
  
  
  } 

//******************************************************
// End of Program
//******************************************************

Check lines 62, 149, and 167. There are statements there that won't ever execute.

Your errors, though, I'm guessing are coming from line 139. You have several errors there, one being that you forgot the modulus operator and how to use it. Research time!
http://www.cplusplus.com/doc/tutorial/operators/

Also, careful with your capitalization. :)

-Albatross

Just line 62? It looks the same as the other ones...(Sometimes it's hard to see the mistakes because I use a desktop computer monitor because the screen of my laptop doesn't work)

As for lines 149 and 167, I should be calling pause_m for the usdt_monitor file unless i should delete the return; parts?




Here's the entire pseudocode:

Function main
Pass In: nothing
Do
Call: clear_m
Display "Welcome to the Fun Program."
Display "Select from the menu."
Display a blank line.
Display "A gets Counting Loop."
Display "B gets Impossible."
Display "C gets Missing Item."
Display "D gets Odd or Even."
Display "E gets Poem."
Display a blank line.
Display "Q quits the program."
Display a blank line.
Display "Enter the letter of your choice.".
Display "Then hit the enter key.".
Display a blank line.
Display "Your choice: --> ".
Get the response for user_choice from the keyboard
Case of user_choice
'A' Call: counting_loop
'B' Call: impossible
'C' Call: missing_item
'D' Call: odd_even
'E' Call: poem
Endcase
While user_choice not equal to 'Q'
Pass Out: zero to the OS
Endfunction

********************

Function counting_loop
Pass In: nothing
For x starts at 0, x < 5, increment x
Display "Are we having fun?"
Endfor
Call: pause_m
Pass Out: nothing
Endfuction

********************

Function impossible
Pass In: nothing
Display "The repeat until loop is impossible in C++."
Call: pause_m
Pass Out: nothing
Endfuction

********************

Function missing_item
Pass In: nothing
Display "This program is missing only the while loop."
Call: pause_m
Pass Out: nothing
Endfuction

********************

Function odd_even
Pass In: nothing
Display a message asking user for an integer value
Get the user_integer from the keyboard
If user_integer modulus 2
Display "Your number was odd."
Else
Display "Your number was even."
Endif
Call: pause_m
Pass Out: nothing
Endfuction

********************

Function poem
Pass In: nothing
Display a 4 line poem
Call: pause_m
Pass Out: nothing
Endfuction

********************

clear_m
and
pause_m
are functions defined in the udst_monitor.h

******************************************************

Potential Variables

Data Type Identifier Name
********* ***************
character user_choice
integer user_integer
integer x
Last edited on
The if should be lowercase. Most if not all (I'm pretty sure all) keywords in C++ are lowercase.

-Albatross
I couldn't see that from my monitor. I was able to fix my code and everything works now.
Topic archived. No new replies allowed.