Need help with probability C++...

I've recently signed up for computer science tutoring classes to prepare for my soon-to-be-chosen major in college. So far I've learned the fundamentals of computer science in general, the parts that make up a computer, introduction to linux, what C++ is, and just now we got into programming. I know the basics like variables, what names cant be used as variables, commands like cout/endl, binary numbers, and and/or/xor/not.

My teacher just gave out a coding homework but the thing is, I don't understand any of it. Not only that, the materials weren't taught (I know for sure). It's probability and (I think) compounded yearly and however I do it on my free C++ program and compiled it, I keep getting errors. I only know how to do addition, subtraction, multiplication, and subtraction at this point.

Here's the assignment:
"There is a lake with 3 different types of fishes living in it: “red”, “green” and “blue”. Population of “red” fishes increases 10% per year, population of “green” increases 15% per year, population if “blue” increases 5% per year.
Also there is a fisherman that catches 100 fishes of each type during the year. If there is less than 100 fishes of certain color then fisherman catches all the remaining fish of that color but does not compensate this shortage from fishes of other colors.

We receive from user three numbers stating the initial number of fishes of each color in the lake. These numbers are the “initial state”. Then we receive from user one more number stating the number of years passed from the “initial state”.
We got to calculate and output the percentage of each fish population in the total amount of fishes after the number of years specified by user will pass.

Please check the input from the user and make sure the input is valid. All the numbers of initial population got to be not less than 0. If user inputs something wrong make him reenter the value until the value is entered correctly. Also make sure that the number of years entered is not less than zero.
Make sure that all input and output is “beautifully” displayed. By that I mean that you got to clearly request from user all the required values. Please make sure that the inputted value does not stick to the input request string (there got to be spaces between them). The same is true when outputting result: no values or strings should stick together."


I'll thank you if you managed to help me! I'll also check some of the code (that I definitely know), to see if they're right and will compile.

You can take your time. I don't care if I can do the homework or not.

I REALLY DONT UNDERSTAND ANY OF IT :(
Last edited on
Well, aside from a few strange wording choices, this is how I interpret your instructions:

1.) Have three integer values that represent the population of each fish type (red, green and blue).
It might be nice to use an array for this, but it's not necessary.

2.) Have another three integer values that represent the rise in population each year for each fish type.

3.) You also need one more integer value to hold the number of years that have passed.

4.) Begin by asking the user to input valid values for the initial population for each fish type. Everytime the user enters a value, you should make sure that it is valid (not less than zero). It might also be a good idea to check if the user actually entered an integer, but that might be out of the scope of the assignment, as that is a bit more advanced.

To check if input is valid, you should put the input in some kind of loop, so that if it isn't valid, the loop starts again, and asks the user to write something else.
(Note, the user shouldn't need to enter values for the population increase, because these values should be constant, and shouldn't change.)

5.) Once you have initial population values for each fish type, you ask the user to input how many years into the future you want to go. Again, if the input is not valid, make the user try again.

6.) Now you have all the input you need. Next, you do the following for each fish:

6a.) Calculate how many fish there will be in x amount of years ('x' being what the user entered for years).

6b.) Print and label the result with the appropriate fish type tag.
Topic archived. No new replies allowed.