c++: struggling with this code a little: http://codepad.org/DIeq6Jo7 Part of the issue is that I'm not used to debugging c++ so I'm sure I'm missing something simple... The questions are posted at the top of the codepad code. But here they are again: Questions: 1. Under "void Randomize();" I have my prototype and var declarations. Am I declaring too much? I use the variables inside the function AND in main and so Visual Studio was acting like it wanted them declared like they are...? 2. In "SingleTrialSimulator()" I am declaring a lot of variables early. Can I wrap some of them togeth
1. For the variable declarations, it's fine to declare those within main, instead of giving them a global scope, since you do not change them inside your SingleTrialSimulator() function (even though you use their values). 2. You can do that, although it may decrease readability :) First you have to declare all of the variables, and then you can do something like: politician1VotesMove = politician1VotesOrig = .5 + (spread/2.0) * voters
Isn't Randomize() defined in random.h? I don't see a need for you to declare it. Since you're passing the variables into SingleTrialSimulator(), the global scope isn't needed. When two or more variables are declared and initialized to the same value, this is legal: int var1 = var2 = 0; You can decide if it's better or not. randomChance isn't needed at all: if( RandomChance(error) ) { } RandomChance(error) will return true or false, why assign it, and you don't need to compare it. Silly question: how many fraction of one votes do you expect to have? A vote really has to be an integer, floats or doubles aren't needed unless you're going to work with extreme numbers.
Join our real-time social learning platform and learn together with your friends!