## followgoat Newbie Poster

Hi, I am in an intro to C++ class, and need help with a homework. The below question requires us to allocate seats in the House for each state according to how large its population is. The entire problem is given all the way below.

I have 2 queries:

1) Im not sure if im reading the question correctly, but this is what i would do : multiply each of the 58 multipliers(2-60) with each of the 50 populations to give about 3000 total values and store this in an array. Then, we have to go through everyone of them, and find the largest 384(435-51) and store them in another array. is this correct?

2) I made an array of size 61 to store the multipliers 2 to 60. I made multiplier and multiplier equal 0 and the rest correspond to their respective mulitpliers. How ever when i ran the code, it kept saying "ambiguous call to overloaded function" for the last line. I couldnt find out what the mistake was ... the code is shown below.

``````int
n; float a;
for
(n = 2; n <= 60; n++)
{
float multiplier;
multiplier = 0;
multiplier = 0;
multiplier[n]= 1/(sqrt(n)*sqrt(n-1));
}
``````

thanks a lot,
victor

``````House of Representatives :

This method assigns seats in the House of Representatives according to a "priority" value. The priority value is determined by multiplying the population of a state by a "multiplier." For example, following the 1990 census, each of the 50 states was given one seat out of the current total of 435. The next, or 51st seat, went to the state with the highest priority value and thus became that state's second seat. This continued until all 435 seats had been assigned to a state. This is how it is done.

P - represents a state's total population

n - represents the number of seats a state would have if it gained a seat (because all states automatically received one seat the next seat gained is "seat two," and the next "seat three," and the next "seat four," and so on.)

The multiplier equals (1 divided by (the square root of n(n-1)) [which is called the reciprocal of the geometric mean]. Computing these values is quite easy using a PC and a good spreadsheet package.

Thus the formula for calculating the multiplier for the second
seat is:

(1 divided by the square root of 2(2-1))
or
1/1.414213562 or 0.70710678

the multiplier for the third seat is:

(1 divided by the square root of 3(3-1))
or
1/2.449489743 or 0.40824829

the multiplier for the fourth seat is:

(1 divided by the square root of 4(4-1))
or
1/3.464101615 or 0.288675134

Once the "multipliers" have been calculated, the next step is to multiply this figure by the population total for each of the 50 states. The resulting numbers are the priority values. Make sure you compute enough multipliers to cover the largest amount of seats in the House of Representatives that any one state stands to gain. Multipliers and priority values must be calculated for the largest number of seats assigned to a state. For example, if the largest number of seats assigned to a state is 50, multipliers and priority values must be calculated for the 50th seat. Compute multipliers for seats 2 through 60. This will assure you have enough multipliers for apportionment.

Once you've calculated priority values for each state for the total anticipated seats, the next step is to rank and number the resulting priority values starting with seat 51 until all 435 seats have been assigned (remember, each state automatically received one seat). Next, tally the number of seats for each state to arrive at the total number of seats in the House of Representatives apportioned to each state.
``````

## VernonDozier 2,218

I didn't get the error that you refer to when I ran your code. I assume you included the cmath library?

You have a few things going on. One, at least at first glance to me anyways, it seems like an odd algorithm to use to calculate the number of House of Representatives seats. Maybe it actually is done that way. I think you are going to have to read through that algorithm several times and reword it it so it makes a little more sense right away. I'm sure the algorithm's fine, but my point is that most people here aren't going to spend the time reading through it several times till they understand it. That's part of the object of your assignment. You are supposed to read through it a few times, work it out on paper, then make it a little more understandable, which is obviously going to take time. Do that first before you even try to code. Make sure you understand the algorithm mathematically, then code it.

Regarding the code, this line:

``float multiplier;``

should be before your loop. Your array will "go out of scope" if you declare it inside the loop as you do. You're basically declaring it, then destroying it over and over again. Also, don't hard code in the numbers for these loop. What do the numbers 2 and 60 represent? I have no idea. Give them descriptive variable or constant names so people can follow the algorithm/code more easily.