Write an interactive C program whose input is a series of 12

Write an interactive C++ program whose input is a series of 12 temperatures from the user. It should write out on file tempdata.dat each temperature as well as the difference between the current temperature and the one preceding it. The difference is not output for the first temperature that is input. At the end of the program, the average temperature should be displayed for the user via cout For example, given the input data Be sure to use proper formatting and appropriate comments in your code. The input should be collected through appropriate prompts, and the output should be labelled clearly and formatted neatly.

Solution

#include <fstream>
#include <iostream>
using namespace std;

int main()
{
   float a,b,c,d,e,f,g,h,i,j,k,l,m;
   ofstream tempdata;
  
   tempdata.open(\"tempdata.dat\");
  
   cout<<\"Please enter 12 temperatures:\"<<endl;
   cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k>>l;
   tempdata<<a<<\"\\t\"<<endl
            <<b<<\"\\t\"<<b-a<<\"\\t\"
            <<c<<\"\\t\"<<c-b<<\"\\t\"
            <<d<<\"\\t\"<<d-c<<\"\\t\"
            <<e<<\"\\t\"<<e-d<<\"\\t\"
            <<f<<\"\\t\"<<f-e<<\"\\t\"
            <<g<<\"\\t\"<<g-f<<\"\\t\"
           <<h<<\"\\t\"<<h-g<<\"\\t\"
            <<i<<\"\\t\"<<i-h<<\"\\t\"
            <<j<<\"\\t\"<<j-i<<\"\\t\"
            <<k<<\"\\t\"<<k-j<<\"\\t\"
            <<l<<\"\\t\"<<l-k<<\"\\t\"<<endl;
          
   tempdata.close();
   m=(a+b+c+d+e+f+g+h+i+j+k+l)/12.0;
   cout<<\"The average temperature is:\"<<m<<endl;
  
   return 0;
          
  
}

tempdata.dat

34.5
38.6 4.1
42.4 3.8
46.8 4.4
51.3 4.5
63.1 11.8
60.2 -2.9
55.9 -4.3
60.3 4.4
56.7 -3.6
50.3 -6.4
42.2 -8.1

 Write an interactive C++ program whose input is a series of 12 temperatures from the user. It should write out on file tempdata.dat each temperature as well as

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site