else statement returning bad float value

I have the following code snippet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    unsigned int j = level2.get_reads();
    unsigned int k = level2.get_read_misses();
    unsigned int l = level2.get_writes();
    unsigned int m = level2.get_write_misses();
    unsigned int o = level2.get_writebacks();
	float h = (float)(b + d) / ((float)(a + c));

	float n;
	if (l2.size == (float)(0))
	  {
		n = 0;
	  }
	else
	  {
		float n = (float)(k) / ((float)(j));
	  }


k = 5943, j = 16002. When the statement float n = (float)(k) / ((float)(j)); is not inside the else block I get n = 0.3714. However, inside the else block I get n = -107374176.0000. How can I get the correct value inside the else block?
Last edited on
Drop the first "float" on line 15. You're defining a variable n inside the else block which hides the variable n in the broader scope.
That did it. You guys are awesome!

Bishop
Topic archived. No new replies allowed.