error c4715? function not return a value for all functions?

this is the program seems to run fine but get that error need to fix asap?

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
#include <iostream>
using std::cin;
using std::cout;
using std::endl;


#include <cstdlib>

int readArray(int,int[]);
int avg(int, const int[]);
int stat(int, const int[], int&,int&,int&);
int histogram(int,const int[],int[]);

int main()
{
const int MAX_SCORE = 50; //the maximum # of scores that a user can enter
int score[MAX_SCORE]; //create storage for up to 50 scores
int nScores = readArray(MAX_SCORE, score); //read array and return count

int avgScore;
int minScore;
int maxScore;

  if (stat(nScores, score, avgScore, minScore, maxScore) == 0)
  {
    cout << "The number of scores entered is: " << nScores << endl;
	cout << "The average of the data entered is: " << avgScore << endl
	<< "The maximum score entered is: " << maxScore << endl
	<< "The minimum score entered is: " << minScore << endl;

	int grade[5] = {0}; //={} is for newer compilers only
	histogram(nScores, score, grade);
	  cout << "As: " << grade[0] << endl;
	  cout << "Bs: " << grade[1] << endl;
	  cout << "Cs: " << grade[2] << endl;
	  cout << "Ds: " << grade[3] << endl;
	  cout << "Fs: " << grade[4] << endl;
  }
  else
	cout << "no data" << endl;
}

int readArray(int n,int accepted[])
{
  char scores[100];
  cout << endl;
    
  //prompt user for input
  cout << "Enter up to 50 test scores (0-100) after last score enter -1 to end: " << endl;
  
  int scoresEntered = 0;
  //read the scores from the keyboard, space and/or newline delimited
  for (int i = 0; i < n; i++)
  {
    cin >> scores;
	cin.ignore(0, ' ');
 
  int entered = atoi(scores);
  accepted[i] = entered;

  if(accepted[i] < 0)
    break;
  else
   scoresEntered++;
  }

  return scoresEntered;

}

int avg(int n,const int accepted[])
{
  int total = 0;
  if(n == 0)
  {
	return 0;
  }

  for(int i = 0;i < n; i++)
  {
    total = total + accepted[i];
  }
    return total / n;
}

int stat(int n,const int accepted[],int& avgs,int& min,int& max)
{
  if(accepted[0] < 0)
  {
	return 1;
  }
  if(n == 0)
  {
	return 0;
  }

    avgs = avg(n, accepted);
	min = accepted[0];
	max = accepted[0];

  for(int i = 0;i < n;i++)
  {
    if(accepted[i] < min)
    {
	  min = accepted[i];
    }
    if(accepted[i] > max)
    {
	  max = accepted[i];
    }
 }
  return 0;
}

int histogram(int nScores, const int accepted[], int letterGrade[])
{
  if(accepted[0] < 0)
  {
    return 0;
  }
  if(nScores == 0) 
  {
    return 1;
  }
 
  for(int i = 0; i < nScores; i++)
  {
    if(accepted[i] >= 90)
    {
	  letterGrade[0]++;
    }
    else if(accepted[i] >= 80 && accepted[i] <= 89)
    {
	  letterGrade[1]++;
    }
    else if(accepted[i] >= 70 && accepted[i] <= 79)
    {
	  letterGrade[2]++;
    }
    else if(accepted[i] >= 60 && accepted[i] <= 69)
    {
	  letterGrade[3]++;
    }
    else if(accepted[i] < 50 && accepted[i] > 0)
    {
	  letterGrade[4]++;
    }
  }
}
When you have compilation errors please always post them in full - or at least show the line number. That way we can explain what it means straight away without having to read all of your code.

That said, you problem looks like it is in the histogram function. If neither of the 2 if condition are true - nothing is returned.

With your avg function just be aware what happens with integer division. Yours is OK with a large number of inputs and a relatively small divisor, but I would have used doubles and converted it to int at the end, just to be sure.
Hi, for your histogram function, u did not include the range from 50 to 59.
Hope this helps :)
Topic archived. No new replies allowed.