Code is not working

When i run my code an error pops up and its say something about the declaration of my variable "SIZE". i have tried numerous ways to solve this problem but i have given up. does somebody know whats wrong with it?

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
96
  // ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <windows.h>

using namespace std;


const int SIZE = 5;

void getScores(float testScores[SIZE]);
void showMenu();
char getChoice(char choice);
float displayResult(char choice, float testScores[SIZE]);

/*
*
*/
int main(int argc, char** argv) {

	float testScores[SIZE];
	char choice;

	getScores(testScores);
	system("CLS");
	showMenu();
	choice = getChoice(choice);
	system("CLS");
	displayResult(choice, testScores);

	return 0;
}

void getScores(float testScores[SIZE])
{
	cout << "what are the 5 test scores? " << endl;

	for (int i = 0; i < 5; i++)
	{
		cin >> testScores[i];
	}
	
}
void showMenu()
{


	cout << " A.) Calculate the average of the test scores. " << endl;
	cout << " B.) Display all test scores. " << endl;

}
char getChoice(char choice)
{
	char letter;


	cout << " Please enter a choice ";
	cin >> letter;
	return letter;
}
float displayResult(char choice, float testScores[SIZE])
{

	float sum = 0;
	float average = 0;

	for (int i = 0; i < 5; i++)
	{
		sum += testScores[i];
	}
	average = sum / 5;
	cout << fixed << showpoint << setprecision(2) << endl;

	if (toupper(choice) == 'a')
	{
		cout << "your average is " << average << endl;
	}
	else if (toupper(choice) == 'b')
	{
		cout << "These are your TestScores " << endl;
		for (int i = 0; i < 5; i++)
		{
			cout << testScores[i] << endl;
		}
		cout << endl;
	}
	else
		cout << "It is invalid" << endl;


}


error output
1
2
3
4
5
6
7
8
9


1>c:\users\gears\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(13): error C2377: 'SIZE' : redefinition; typedef cannot be overloaded with any other symbol
1>          c:\program files (x86)\windows kits\8.1\include\shared\windef.h(190) : see declaration of 'SIZE'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Windows (in windef.h included in windows.h) declares type called SIZE.

Because of that you cannot have variables/types called SIZE in your program.

Note that you do not really need windows.h header because you do not use anything from it and you could safely delete it enabling use of name SIZE.

Alternative way is to rename your variable. Or to have a namespace and not pollut global namespace with your variables.
Topic archived. No new replies allowed.