The code is supposed to be in c++, I am having problems printing my results, so
ID: 3744198 • Letter: T
Question
The code is supposed to be in c++, I am having problems printing my results, so I want to see how one of the experts would do it.
Some Background Hopefully you remember that a linear model is created by specifying a slope and an intercept where you can use the equation y-slope * x + intercept (y is the temp, x is the year). I gathered (see spreadsheet) the average global temp in degrees Fahrenheit, 1880-2012, and fit a linear model to it. The slope is 0.01173 degreesF/year and the intercept is 34.3491 degreesF. Using this information, you will write a program that does as follows. Program Specifications Your program will do the following: 1. Take as input two values: a. a year, as a long b. a slope, as a double 2. Print three results: Print the temperature for the year read in above based on the slope and intercept provided in the Background section. Print it as a double of precision 2. a. b. Print the year when, given the temperature calculated in a. above, a temperature 7 degrees greater will occur again using the slope and intercept provided in the Background. Print it as a rounded long. c. Print the year when, given the temperature calculated in a above, a temperature 7 degrees greater will occur using the second input, a new input slope, and the intercept provided in the Background. Print it as a rounded long.Explanation / Answer
CODE :
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double m = 0.01173; // slope
double c = 34.3491; // intercept
long y; // temperature
double x; // year
cout << "Enter a year and a new slope." << endl;
cin >> y;
cin >> x;
double temp = m*y + c;
cout << fixed;
cout << setprecision(2); // fixes the number of digits to show after decimal
cout << "Temperature : " << temp << endl;
temp = temp + 7 - c;
cout << setprecision(0);
cout << "Year : " << (temp/m) << endl;
cout << "Year : " << (temp/x) << endl;
return 0;
}
*************NOTE*************
If there is any doubt, feel free to ask in the comments. :)
If everything is clear, please rate accordingly :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.