Dog years
Lesson 22 of 32 in Coddy's Coding Problems course.
Challenge
MediumWe think that one dog year is equal to 7 human years. That's not true, on average the first dog year is equal to 15 human years, the second dog year is equal to 9 human years, from the third to the sixth each is equal 4 human years and every next year after that is equal to 5 human years.
If you know how old is your dog in dog years, calculate how old it is human years.
Write a function named dogYears that given a natural number N from input representing the years of your dog. Return how old is your dog in human years.
Input
2
Output
24
Input
4
Output
32
Explanation #1: 2 dog years are equal to 15 + 9 = 24 human years
Explanation #2: 4 dog years are equal to 15 + 9 + 4 + 4 = 32 human years
Try it yourself
int dogYears(int a1) {
// Write code here
}All lessons in Coding Problems
1Course Introduction
Introduction