Unusual problem AFTER successful compiling

Hi, first of all I must say now that I'm french-canadian so my english is not that good and I'm a !"/BEGINNER\"!, I will understand everything you will say in your answer though.

Here's my problem : I had my first C++ class today. It was not that hard because I did some C++ before but, after writing the program the teacher wanted us to, there was an error when I tried to run the program : it says that my "valeur_PS" variable is not defined, but it is!

Also, that kind of error never happened to me before, it is strange because after compiling, everything seems all right...

Can you help me?

Here's the code (there are some french variables in it, sorry) :

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
#include <iostream>

using namespace std;

const int SIZEVECT = 10;   

int produitScalaire(int [], int []);

int main()
{
	int v[SIZEVECT] = {0,0,2,-2,-2,-2,-1,2,2,-3};
    int d[6*SIZEVECT] = {-1,0,0,1,1,-1,0,-3,3,-2,-2,-1,-2,0,-1,3,3,-3,2,-1,0,0,3,0,3,-1,1,1,0,1,1,-2,-2,3,-2,-3,0,2,1,-2,-1,0,3,-2,2,1,-1,-2,0,0,-2,1,-2,-1,1,-1,-1,1,-1,2};
	int y[SIZEVECT]; 
	bool r[SIZEVECT];
	
	int valeur_PS;

	for (int vector_no = 0; vector_no < 6; vector_no++) 
	{
		for (int element_no = 0; element_no < SIZEVECT; element_no++) 
		{
			y[element_no] = d[((vector_no) * 10) + element_no];
		}
		
		valeur_PS = produitScalaire(v, y);

		if (valeur_PS = 0)
		{
			r[vector_no] = true;
		}
		else
		{
			r[vector_no] = false;
		}
                for (int i = 0; i < SIZEVECT; i++)
	        {
		        cout << r[i] << "\t";
	        }

	cout << "\n" << endl;
	}		
		
	return 0;
}

int produitScalaire(int v[], int y[])
{
	int valeur_PS;

	for (int elementPS_no = 0; elementPS_no < SIZEVECT; elementPS_no++)
	{
		valeur_PS = valeur_PS + (v[elementPS_no] * y[elementPS_no]);
	}

	return valeur_PS;
}



The error message says (after successful F7 and a CTRL-F5) :

Debug error!

Run-Time Check Failure #3 - The variable "valeur_PS" is being used without being initialized
The error is on line 52.
valeur_PS = valeur_PS + .... is invalid because at this point, you have only declared valeur_PS (at line 48) but have not stored a value in it.

P.S. The variable valeur_PS declared on line 16 is not the same as the variable valeur_PS at line 48 even though they have the same names. They are each local to the functions they were declared in.
Last edited on
Thank you very much Maese909!!! It solved the problem and now my program works! I will pay more attention next time, thank you again!
Last edited on
Topic archived. No new replies allowed.