Calling Void Function

Hi,
I am writing a program to evaluate test scores from a file. The lesson we're supposed to learn is how to write and call void functions. In this problem, we are to read a 20 character key, then print ID numbers (7 digits), and scores. Scores are to be evaluated with a void function. This program compiles, but does not seem to be calling the function. I tested by inserting a cout statement in the void function to see if it even got there.

I am also having trouble with my while loop in main(). I'm probably missing something very simple, but it prints the last studentID twice. Why is it doing this?

Here is my code:

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
//***************************************************************************************************
//Nicholas Keckeisen, CSC 210-DL01, Fall 2012, Project 7, October 5th, 2012
//This program evaluates scores in the file "scores.dat" and outputs the number correct corresponding
//to the students ID number. Additionally, it verifies proper formatting of scores.
//IDE is Notepad++
//Instructions: Run program
//***************************************************************************************************

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void printHeading();
void evaluate(string key, string answers);

int main()
{
//Variables
string key;
string answers;
int score;
string studentID;
ifstream inData;

//Heading
printHeading();

//Open
inData.open("scores.dat");
if (!inData)
{
	cout << "Can't open scores.";
	return 1;
}

//Input
getline(inData, key);
while (inData)
{
inData >> studentID;
cout << studentID << "  ";
inData >> answers;
void evaluate(string key, string answers);
}
return 0;
}

void printHeading()
{
cout << endl << "Nicholas J. Keckeisen" << endl << "Project Number 7" << endl << "CSC 210-DL01" << endl << "Summer, 2012" << endl << endl;
}

void evaluate(string key, string answers)
{
cout << "In void function" << endl;
char keyChar;
char answerChar;
int score;
int count;

if (key.length() > answers.length())					//Check for too few answers
{
cout << "Too Few Answers" << endl;
return;
}
if (key.length() < answers.length())					//Check for too many answers
{
cout << "Too Many Answers" << endl;
return;
}

score = 0;
count = 1;
keyChar = key[count];
answerChar = answers[count];

while (count <= 20)
{
if (answerChar != ('a' || 'b' || 'c' || 'd' || 'e' || 'f'))			//Checks for valid answers
	{
	cout << "Invalid Answers" << endl;
	return;
	}
if (keyChar == answerChar)											//Running Tally
	{
	score++;
	}
count++;
keyChar = key[count];
answerChar = answers[count];

}
cout << score << endl;
}


and the .dat file:

1
2
3
4
5
6
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
3332221 abcdefghijklmnopqrst


Any help greatly appreciated!

EDIT: Hey folks, just read the forum rules. Trying to respect those, just a hint or two would be appreciated, Sorry!
Last edited on
Call to void changed to:
 
evaluate(key, answers);


and it calls properly.

Unfortunately, I am still printing the last ID number twice, and my checks for valid answers (line 80) always failes and prints "Invalid Answers"

Thoughts?
Last edited on
1
2
3
4
5
6
//Input
getline(inData, key);
while (inData)
{
   inData >> studentID; //Suppose that this fails,
   cout << studentID << "  "; //you keep processing 
your crappy indentation lost me, but I suppose that you may change it to while(inData>>studentID>>answers){

About line 80, you can't do it like that.
¿what do you think if (answerChar != ('a' && 'b' && 'c' && 'd' && 'e' && 'f')) will do?
Topic archived. No new replies allowed.