TPS 2: Variables
- Due Feb 10, 2021 by 10am
- Points 1
- Submitting a file upload
- File Types doc and docx
- Available after Feb 10, 2021 at 9am
See TPS 1: Command Line for instructions on how to update your TPS document if you've forgotten. Here's the question to answer:
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 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;
}
Submit your TPS document here (you should be able to submit it directly through Drive if you're only logged into your Endicott Gmail account in your browser).