Dog Years C++ Bug if you own a Dog younger than 2 Years

When reading the instructions I immediately noticed they were not considering pets younger than 2 without acknowledging it. Am I missing something from the instructions to my code?


int main() {

int dog_age = 1;
int early_years;
int later_years;
int human_years;

early_years = 20;
later_years = (dog_age-2)*4;
human_years = early_years + later_years;

std::cout << “My name is Bill! Ruff ruff, I am " << human_years << " years old in human years.”;

With this, the chart for the dog age looks like

Dog-Age 1 -- Human Age 16 (20 + -4)
Dog-Age 2 --  Human Age 20 (20 + 0)
Dog-Age 3 --  Human Age 24
Dog-Age 4 --  Human Age 28
Dog-Age 5 --  Human Age 32

The variable names could be clearer, and I don’t know about the scientific integrity of the formula… but it does cover young dog-ages.

According to the description:

Here’s how we can convert your dog’s age into human years:

  • The first two years of a dog’s life count as 21 human years. (OOPS UPDATED THIS FROM 20 to 21.
  • Each following year counts as 4 human years.

So a one-year-old dog is 10.5 years old in human years, and a two-year-old dog is 21 years old in human years…

So it SHOULD look like:

Dog-Age 1 -- Human Age 10.5   (21+ -4) =17
Dog-Age 2 --  Human Age 21 (21 + 0) =21

Yea i don’t have access to the problem. But I was just saying that with that code you can still have dogs younger than 2 years-old.

If the first 2 years are different, then maybe you want to set up a base-case in your code. (meaning, for the first 2 years the code behaves differently, afterwards it stays consistent).

Yes, I understand. We haven’t been taught conditionals yet, the solution deems this acceptable, so I’m just pointing this out as a bug in their instructions.