integer being reset to zero

I'm trying to figure out why my code keeps resetting the power once entered, back to zero once the function goes back to main. Any ideas fellas?

PS: This is just a code snippit.

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
 const int MAX_POWER = 13;
const int MAX_FILENAME = 255;

void GetPower(int power);                                  // deleted ampersand
void GetFilename(char filename[]);
void ConvertToUpper(char filename[]);
void InitPascal(int power, int pascal_tri[MAX_POWER][MAX_POWER]);                       // added MAX_POWER
void PrintPascal(char filename[], int power, int pascal_tri[MAX_POWER][MAX_POWER]);     // added MAX_POWER

int main()                                                 // changed Main to main
{
	int power;
	int pascal_tri[MAX_POWER][MAX_POWER];                  // Added underscore and MAX_POWER
	char filename[MAX_FILENAME];

	GetPower(power);                                       // deleted ampersand
	GetFilename(filename);
	InitPascal(power, pascal_tri);                         // Fixed naming
	PrintPascal(filename, power, pascal_tri);
	return 0;
}
void GetPower(int power)
{
	char str[3];

	cout << "Please enter the power of the equation (1 - " << MAX_POWER - 1 << "): ";
	cin >> power;

	while (power > MAX_POWER && power <= 0)
	{
		cout << "You have entered an invalid power.";
		cout << "\nThe number must be from 1 to " << MAX_POWER - 1;
		cout << "\n\nPress the enter key to try again";
		cin.ignore(cin.rdbuf()->in_avail());
		cin.getline(str, 2, '\n');
		cin.ignore(cin.rdbuf()->in_avail());
		cout << "Please enter the power of the equation (1 - " << MAX_POWER << "): ";
		cin >> power;
	}
}                          // deleted ampersand 
> deleted ampersand
¿are you serious?

Arguments passed by value and by reference
http://www.cplusplus.com/doc/tutorial/functions/
This is a debugging project. A lot of things didn't make sense in its original form.
set the power variable as a static variable.
Topic archived. No new replies allowed.