Need help with return Values

So I have this code in which I know everything works, except the return value for my two integer functions. I have calculated what I wanted to know, and already plugged them into variables, so what value should I be returning, when I really feel I don't need one?
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "GradeAnalysis.h"

using namespace std;

int GetInput(ifstream&, string&, string&, int&, int&, int&, int&, int&, int&);
int AnalyzeGrade(ifstream&, string&, string&, int&, int&, int&, int&, int&,
                 int&, int&);
void WriteOutput(ifstream&, ofstream&, string&, string&, int&, int&);

/*
 *
 */
int main()
{
    
    ifstream infile;
    ofstream outfile;
    infile.open("./ProgGrades2.txt");
    outfile.open("./GradeReporttest.txt");
    
    string lastName, firstName;
    
    int score1, score2, score3, score4, score5;
    int max, location;
    
    while(GetInput(infile, lastName, firstName, score1, score2, score3, score4,
                   score5, max))
    {
        if (score1 == -99)
            break;
        cout << lastName << " " << firstName << " " << score1 << endl;
        AnalyzeGrade(infile, lastName, firstName, score1, score2, score3,
                     score4, score5, max, location);
        
        WriteOutput(infile, outfile, lastName, firstName, max, location);
    }
    
    infile.close();
    outfile.close();
    return 0;
}

int GetInput(ifstream& infile, string& lastName, string& firstName, int& score1,
             int& score2, int& score3, int& score4, int& score5, int& max)
{
    char firstChar;
    string last1, last2, firstChar1;
    
    infile >> firstChar;
    
    if (isupper(firstChar))
    {
        infile >> last1 >> firstName;
        firstChar1 = firstChar;
        lastName = firstChar1 + last1;
    }
    else if (islower(firstChar))
    {
        infile >> last1 >> last2 >> firstName;
        firstChar1 = firstChar;
        lastName = firstChar1 + last1 + " " + last2;
    }
    
    infile >> score1 >> score2 >> score3 >> score4 >> score5;
    return ;//What should I return?
}

int AnalyzeGrade(ifstream& infile, string& lastName, string& firstName,
                 int& score1, int& score2, int& score3, int& score4, int& score5,
                 int& max, int& location)
{
    int score[5];
    max = 0;
    score[0] = score1;
    score[1] = score2;
    score[2] = score3;
    score[3] = score4;
    score[4] = score5;
    for (int i = 0; i < 5; i++)
    {
        if (score[i] > max)
        {
            max = score[i];
            location = i+1;
            i=i-1;
        }
    }
    fill_n(score, 6, 0);
    return ;//What should I return?
}

void WriteOutput(ifstream& infile, ofstream& outfile, string& lastName,
                 string& firstName, int& max, int& location)
{
    string studentID = lastName + " " + firstName;
    outfile << "\n" << setw(19) << studentID << setw(14) << location << " " <<
    max;
}


I'm tried returning max, location, and any of the score values, but they always gave an undesirable output, which is supposed to look like:

1
2
3
4
5
6
7
8
9
Programmer: Jane Austin
CS 1044 Project 4 Fall 2013

Student	Submission	Grade
Boole, George	2	105
Pascal, Blaise	3	92
Babbage, Charles	1	100
Kepler, Johannes	2	102
Clown, Bozo	5	62


And the input looks like:

1
2
3
4
5
6
Boole, George	98	105	-1	-1	-1
Pascal, Blaise	63	48	92	92	92
Babbage, Charles	100	97	100	98	-1
Kepler, Johannes	75	102	100	-1	-1
Clown, Bozo	0	6	6	57	62
Fini, End	-99	-99	-99	-99	-99
if you don't want or need to return anything you could change it to a void function. Why do extra things if you don't have too?

the same way you have your writeoutput function void you can set the other functions that way too.

Then delete the return lines.


1
2
3
4
void GetInput(ifstream&, string&, string&, int&, int&, int&, int&, int&, int&);
void AnalyzeGrade(ifstream&, string&, string&, int&, int&, int&, int&, int&,
                 int&, int&);
void WriteOutput(ifstream&, ofstream&, string&, string&, int&, int&);
That ends up with my while loop not working, "error: value of type 'void' is not contextually convertible to 'bool'".
Topic archived. No new replies allowed.