so I'm currently writing an assignment for my data structures class that's giving me a headache in the most basic place possible. We're working on the Hungtington-Hill method in conjunction with priority queues, and when I try and do my simple division to get the "priority" which is equal to the population of a state divided by the geometric mean, I'm getting really large numbers. The vars and method inside my state class look like this:
class State{
private:
string state;
int pop;
int reps;
double priority;
};
void State::calculatePriority(){
double temp = (double)reps * ((double)reps + 1.0);
priority = (double)pop/sqrt(temp);
}
The method calculatePriority() gives me crazy output, where it'll read in like this:
State: California
2010 Census Population: 37253956
Representatives: 1
Priority: 0
And post calculatePriority() I get this:
State: California
2010 Census Population: 37253956
Representatives: 1
Priority: 2.63425e+07
Is there a logical mistake I'm making here? I'm not sure what the issue is. It may be with the sqrt() method I am not sure. I at first thought it was because of the (double) cast, so I changed all the vars to doubles, but I encountered the same issue.