Several problems with recent programs...

I am working with a structure and switch statements as part of a homework assignment, but for no explainable reason, it is giving me the error

"; missing before ." Which is nonsense. Not only that, it gives these errors twice each for the same line.

Here is short example of the switch statement I am using.

1
2
3
4
5
6
7
8
switch (key) //key is type char.
{
case '1':
case '2':
case '3':
phoneTones.rowTone = 679; //phoneTones is the name of the structure, and rowTone is one of the members of the structure.
break;
}


For the next one, I am dealing with I/O again, this time using arrays.

I dunno where the logic error in my program is, but for some reason, the output file is blank when the arrays themselves are not. Here is example of how I am using the of_stream.

 
writing << idArray[i] << storeNum[i] << qtyArray[i] << endl;


When checking the output file from this, it is blank, and it should not be. What could be causing this? Cause everything else works fine before that point.

Then with the next one, I am getting the Linker Error LNK2019. One of my functions: overTime, is mentioned as the cause of it. The problem is, I have it's function prototype, correctly stated no less, before the main function as follows.

 
int overTime (const worker g[], int numb);


and it is implemented in the main function as follows.

 
int over = overTime (workr, number); // workr is the instance of the worker structure, number is a //previously declared int variable. 


I have no idea what could be causing this error, here is the function as follows.
1
2
3
4
5
6
7
8
9
10
11
12
int overTime (const worker g[], numb)
{
int count = 0;
for(int i = 0; i < numb; i++)
{
if(g[i].hourworked < 40)
      continue;
else
      count++;
}
return count;
}


I have another program, named hangman, which was given as a previous assignment. The problem is that, for some reason, one of the functions doesn't work as I think it logically should from looking at the code. Here is the function:

1
2
3
4
5
6
7
8
9
10
void updateTemplate(const char secretword[], char guessLetter, guessTemplate[])
{
for(int i = 0; guessTemplate[i] != '\0'; i++)
{
 if(secretword[i] == guessLetter)
         guessTemplate[i] = guessLetter;
   else
         continue;
}
}


I am currently at a loss for why this function is not working properly right now.

Currently these are the main things that are holding me up from completing all of my assignments for this semester, and I sorely do not wish to fail.
Last edited on
1) Check before it. There is probably an error on a previous line somewhere.

2) No idea, are you sure you are writing to the file you think you are? Are you opening it correctly?

3) You are missing an int before numb on your definition, not sure if that would cause that error though. Are these in different files or one big file?

4) guessTemplate[] does not have a type. Anyway: http://cplusplus.com/forum/articles/40071/#msg218019
1) Did. There shouldn't be any errors. The switch statements I am using literally make up the entirety of the function they are in. In example, the function looks like this:

1
2
3
4
5
6
7
8
9
10
11
phoneTones keyToTones(char key)
{
switch(key)
{
case '1':
case '2':
case '3':
phoneTones.rowTone = 679; //phoneTones is the name of the structure, and rowTone is one of the members of the structure.
break;
}
}


2) I should've mentioned this, dang it: You get to name a file for output, and it doesn't have to be a premade file. The file name is a variable called "fileName" which you input, which the program creates itself for output.

3) One big file. This is all in one program.

4) forgot to put this as well: guessTemplate's type is char.
Last edited on
Sorry to double post, but I thought I would bump this and give the entire functions for the offending codes.

Starting with my problem with phone.cpp, which is the error "missing ';' before '.'"

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
phoneTones keyToTones (char key)
{
	switch (key)
	{
		case '1':
		case '2':
		case '3': 
			phoneTones.rowTone = 697;
				break;
		case '4':
		case '5':
		case '6':
				phoneTones.rowTone = 770;
				break;
		case '7':
		case '8':
		case '9':
				phoneTones.rowTone = 852;
				break;
		case '*':	
		case '0':
		case '#':
				phoneTones.rowTone = 941;
				break;
		default:
				cout << "Not valid number...";
				break;
	}
	switch (key)
	{
		case '1':
		case '4':
		case '7':
		case '*':
				phoneTones.colTone = 1209;
				break;
		case '2':
		case '5':
		case '8':
		case '0':
				phoneTones.colTone = 1336;
				break;
		case '3':
		case '6':
		case '9':
		case '#':
				phoneTones.colTone = 1447; 
				break;
		default:
		cout << "Not valid number";
			break;
	}
}


As you can plainly see, there shouldn't be a problem...Unless I am missing something obvious, which I wouldn't rule out.

Next is the output function that won't write anything in my I/O array program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bool extractData(const char newFileName[], int requestId, int baseQty, const long idArray[], const int storeArray[], const int qtyArray[], int count, int& newcount)
{
ofstream writing;
writing.open(newFileName);
if (!writing)
	{
		cout << "File could not be opened.\n";
		return false;
	}
else
for(int i = 0; i < count; i++)
{
if (idArray[i] == requestId)
{
if(qtyArray[i] <= baseQty)
			writing << idArray[i] << " " << storeArray[i] << " " << qtyArray[i] << endl;
			newcount++;
else
		continue;
}
return true;
}
}


I'll post my workergroup program in another post, cause it would be horrendously long.

EDIT: New problem in the program above in the same function, getting an "illegal else without mathing if" error. Also, updated the function.
Last edited on
1
2
3
4
5
phoneTones keyToTones (char key)
{
  ...
  return ... //I didn't see you return a phoneTones from this function
}
Topic archived. No new replies allowed.