Ask Experts Questions for FREE Help !
Ask
    ben1234's Avatar
    ben1234 Posts: 2, Reputation: 1
    New Member
     
    #1

    Feb 17, 2008, 02:20 AM
    I really I\IeeD I-IeLp with this C++ programing
    Hello,

    I seem to be stuck writing this program that inputs a series of 12 temperatures from the user. It should write out on the file "tempdata.dat" each temperature and the difference between the current temperature and the one preceding it. The differne is not output for the first temperature this is input. At the end of the program, the average temperature should be displayed for the user via cout. Here's the given input data:

    34.5 38.6 42.4 46.8 51.3 63.1 60.2 55.9 60.3 56.7 50.3 42.2

    File tempdata.dat would contain:

    34.5

    38.6 4.1

    42.2 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

    This is what I have come up with so far but I got stuck as to what to do next about the computation in getting the difference between the temperatures. Can someone please help.
    ben1234's Avatar
    ben1234 Posts: 2, Reputation: 1
    New Member
     
    #2

    Feb 17, 2008, 02:22 AM
    here is what I come up so far
    // program to calculate average and different temperature
    #include <iostream>
    #include <fstream>
    #include <iomanip>

    using namespace std;

    int main()
    {
    //declare variable
    ofstream outfile; // out file stream variable

    float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12;
    double average;
    float diff1,diff2,diff3,diff4,diff5,diff6,diff7,diff8,di ff9,diff10,diff11;
    outfile.open("tempdata.dat");
    outfile<<fixed<<showpoint;
    outfile<<setprecision(2);





    cout<<"Enter a series of 12 temperature in the format:temp1 temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10 temp11 temp12";

    cin>>temp1, temp2, temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10,t emp11,temp12;
    diff1=temp1-temp2;
    diff2=temp2-temp3;
    diff3=temp3-temp4;
    diff4=temp4-temp5;
    diff5=temp5-temp6;
    diff6=temp6-temp7;
    diff7=temp7-temp8;
    diff8=temp8-temp9;
    diff9=temp9-temp10;
    diff10=temp10-temp11;
    diff11=temp11-temp12;

    average= static_cast <double>(temp1+temp2+temp3+temp4+temp5+temp6+temp7 +temp8+temp9+temp10+temp11+temp12)/12;
    cout<<average;
    return 0;
    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

C++ programing compiler [ 8 Answers ]

Does anyone know where I can find a free or really cheap programin g compiler?

C programing tackle [ 3 Answers ]

hello all I was thinking of a program that converts the integer you entered into english alphabet for example if a user types 1234 then the out put should be one two three four; but the number of digits to be entered should not be fixed any digit integer if you solve...

Programing [ 2 Answers ]

Hey Could someone please give me a name of a site that explains in depthly how to make your own computer program on windows me or could some very nice person explain it to me in extrem depth how to make your own program? Much apperciated

I want to learn about programing [ 11 Answers ]

I'm somewhat of a computer geek and I want my knowledge to increase this site helps a lot but I want to learn about programing, is there anybooks for beginners like me that will get me started


View more questions Search