# Thread: /= doesn't do what you think it does?

1. To see what was going on to the example, I added this wide line:

cout << i << " i | " << namesmap[i] << " namesmap[" << i << "] | " << kFmap[k][namesmap[i]] << " kFmap[" << k << "][" << nam\
esmap[i] << "] | ";

This way, I can see what is going on to what where. The output becomes this:

k = 0
1 i | one namesmap[1] | 5 kFmap[0][one] | 5 kFmap | 2 | 0.2 |
2 i | two namesmap[2] | 10 kFmap[0][two] | 10 kFmap | 1 | 0.1 |
3 i | three namesmap[3] | 5 kFmap[0][three] | 5 kFmap | 0.2 | 0.02 |
4 i | four namesmap[4] | 20 kFmap[0][four] | 20 kFmap | 1 | 0.1 |

k = 1
1 i | one namesmap[1] | 5 kFmap[1][one] | 5 kFmap | 3 | 0.3 |
2 i | two namesmap[2] | 5 kFmap[1][two] | 5 kFmap | 0.3 | 0.03 |
3 i | three namesmap[3] | 5 kFmap[1][three] | 5 kFmap | 0.03 | 0.003 |
4 i | four namesmap[4] | 20 kFmap[1][four] | 20 kFmap | 1.1 | 0.11 |

For k=1, we can now see that he's accessing F[5] three times, producing the behaviour he observes, as it redivides the quotient it just calculated. As pointed out, he accesses F[20] which is uninitialised (hence why he got 1.1).

Cheers.

2. Originally Posted by pedestrian879
To see what was going on to the example, I added this wide line:

cout << i << " i | " << namesmap[i] << " namesmap[" << i << "] | " << kFmap[k][namesmap[i]] << " kFmap[" << k << "][" << nam\
esmap[i] << "] | ";

This way, I can see what is going on to what where. The output becomes this:

k = 0
1 i | one namesmap[1] | 5 kFmap[0][one] | 5 kFmap | 2 | 0.2 |
2 i | two namesmap[2] | 10 kFmap[0][two] | 10 kFmap | 1 | 0.1 |
3 i | three namesmap[3] | 5 kFmap[0][three] | 5 kFmap | 0.2 | 0.02 |
4 i | four namesmap[4] | 20 kFmap[0][four] | 20 kFmap | 1 | 0.1 |

k = 1
1 i | one namesmap[1] | 5 kFmap[1][one] | 5 kFmap | 3 | 0.3 |
2 i | two namesmap[2] | 5 kFmap[1][two] | 5 kFmap | 0.3 | 0.03 |
3 i | three namesmap[3] | 5 kFmap[1][three] | 5 kFmap | 0.03 | 0.003 |
4 i | four namesmap[4] | 20 kFmap[1][four] | 20 kFmap | 1.1 | 0.11 |

For k=1, we can now see that he's accessing F[5] three times, producing the behaviour he observes, as it redivides the quotient it just calculated. As pointed out, he accesses F[20] which is uninitialised (hence why he got 1.1).

Cheers.
Thank you.