Think Pair Share 3
- Due Feb 3, 2020 by 10am
- Points 1
- Available after Feb 3, 2020 at 9am
Write your answer to the question below on a piece of paper.
Consider the following program that converts human years to dog years. If the user enters their age as 18, it should display "You are 85 in dog years." (using the formula Links to an external site. 10.5 dog years for the first two human years, then 4 dog years per human year thereafter). However, it prints "You are 84 in dog years". Identify why that happens and how to fix it.
#include <iostream>
using namespace std;
int main()
{
const int FIRST_TWO_YEARS_FACTOR = 10.5;
const int REMAINING_YEARS_FACTOR = 4;
int humanAge;
cout << "How old are you (must be at least 2)?" << endl << "> ";
cin >> humanAge;
cout << "You are "
<< FIRST_TWO_YEARS_FACTOR*2 + (humanAge-2)*REMAINING_YEARS_FACTOR
<< " in dog years." << endl;
return 0;
}