Stack around variable 'scores' was corrupted

How do i get rid of this debug error? just learning.plz help

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
 #include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <fstream>
using namespace std;

void computeLetterGrade(double grade[]);
void readInput (float scores[], int len,double grade[]);
void computeGrade(float score[],double grade[]);
	int main (){

	float scores[5]; 
	double grade[1];
	 readInput(scores, 5, grade);
	 cout<<endl;
	 computeLetterGrade(grade);

	








	return 0;

}
void readInput (float scores[], int len,double grade[]){ 
	string name, last;
	cout << "Please enter the student's full name -----> " << name;
	cin >> name>> last;
	cout << "Please enter the scores in the following order" << endl;
	cout<<endl;
	cout << "Homework , quizzes , mid- term , final , attendance  -----> ";
	for (int i=0; i<len; ++i)
	{	cin >> scores[i];}
		int i=0;
	if (scores[ i] >100)
	{cout<<""<<endl;
		cout <<"ERROR..score over 100 not possiable." <<endl;

	}
 else {cout<<"................................................................................"<< endl;
	cout << "Homework   ="<< scores[0]<<endl;
	cout << "Quizzes    ="<< scores[1]<< endl;
	cout << "Mid-term   ="<< scores[2]<< endl;
	cout << "Final      ="<<scores[3]<< endl;
	cout << "Attendance ="<<scores[4]<< endl;
	cout<<"................................................................................"<< endl;
	cout<<""<<endl;
	cout <<"The final grade for the student: " << name<<" "<< last<< " is as follows:"<< endl;}

computeGrade(scores, grade);

 cout<<endl;
 

}
void computeGrade(float scores[], double grade []){
	double homework , quizzes , midterm , final , attendance;
	homework = scores[0]*0.3;
	quizzes  = scores[1]*0.1;	
	midterm  = scores[2]*0.25;
	final   = scores[3]*0.3;
	attendance = scores[4]*0.05;
 
	double sum( homework + quizzes + midterm + final + attendance);
	cout << "Grade in 100% = "<< setprecision(4)<< sum <<  endl; 
	grade [1]= sum ;
}
void computeLetterGrade(double grade[]){
	
	if (grade [1]>= 90)
	cout <<"Letter Grade = A"<<endl;
	else if (grade [1]>= 80)
		cout <<"Letter Grade = B"<<endl;
	else if (grade[1]>=70)
		cout <<"Letter Grade = C"<<endl;
	else if (grade [1]>=60)
		cout <<"Letter Grade = D"<<endl;
	else if (grade[1]< 60)
		cout <<"Letter Grade = E"<<endl;





}
Don't forget arrays in C++ use zero based indexing meaning they all start from 0 not 1. You defined your grade array as double grade[1]; which means it has 1 element (accessed by grade[0])

In your computeLetterGrade() function you are trying to access the results as grade[1] causing a memory error.
Thanks but it still is something wrong with my "scores" =/
You're making the same mistake in computeGrade. Line 73. That should be grade[0].
OK IT WORKS NOW THANKS!!!!
Topic archived. No new replies allowed.