I keep getting an error with my code but it seems fine?

Hello my fellow peers! I coded out this program for an assignment that is due next week and for some reason I get an error that says "Run-Time Check Failure #3 - The variable 'Class_Count' is being used without being initialized." Also when I keep continuing I keep getting the same error "Run-Time Check Failure #3 - The variable 'Student_Total' is being used without being initialized." Then when I keep going I get the same thing but for each of my variables I declared "Run-Time Check Failure #3 - The variable 'Class_Total' is being used without being initialized." Can someone tell me how to fix this and let me know so I can learn from this? Thank You my fellow peers! Also I would like to state that my first programming language I learned was Python so I maybe mixed it up but I don't see what's wrong with it.

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
/*---30,000 Foot View---
Input Variables
   -Name
   -Test Score
Calculate outupts
   -Student Average
   -Class Average
Output calculations to user
   -Student Name
   -5 Test Scores
   -Student Average
   -Class Average 
*/

#include <iostream>
#include <string>

using namespace std;

int main(){
	//Delcare Variables
	double Student_Total;
	double Student_Average;
	double Class_Total;
	double Class_Average;
	double Class_Count;
	double Test;
	double Counter;
	string Name;
	string User_Answer;
	User_Answer = "Yes";


	while ( User_Answer != "No" ){
		

		Class_Count = Class_Count + 1;

		cout << "What is the Student's name? ";
		cin >> Name;

		for (int Counter = 1; Counter < 6; Counter ++ ){
			
			cout << "Enter Test Score ";
			cin >> Test;

			Student_Total = Student_Total + Test;
			Student_Average = Student_Total / 5;
		}
	
		Class_Total = Class_Total + Student_Average;
		Student_Total = 0.0;

		cout << Name << "'s Average Test Score is: " << Student_Average;
		cout << "Do you want to add another student?(Yes or No) ";
		cin >> User_Answer;
	}
	
	Class_Average = (Class_Total / Class_Count);
	cout << "The class average is: " << Class_Average;
	

	system("pause");

	return 0;
}
Last edited on
self-explanatory errors:
e.g.
Class_Count = Class_Count + 1;

You have not initialised Class_Count, so at this point the value in Class_Count is complete garbage. So 1 + garbage is still garbage.
@mutexe Thank you for spotting out the error! But can you show me how I would then initialize it in C++? Thanks
http://www.cplusplus.com/doc/tutorial/variables/
"Initialization of variables" section.
Thank you so much I got it working perfectly now! You're the best!
Topic archived. No new replies allowed.