Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C (https://www.askmehelpdesk.com/forumdisplay.php?f=438)
-   -   Writing a program that outputs this information (https://www.askmehelpdesk.com/showthread.php?t=311423)

  • Feb 1, 2009, 07:32 AM
    SammiD08
    Writing a program that outputs this information
    Write an interactive C++ program that inputs a series of 12 temperatures from the user. It should write out on file "tempdata.dat" each temperature and 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 use via cout. For example, given the following 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.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

    Be sure to use proper formatting and appropriate comments in your code. The input should have appropriate prompts, and the output should be labeled clearly and formatted neatly.

    I've been looking at this problem for the past week... PLEASE HELP!!
  • Feb 7, 2009, 10:50 PM
    JoshP
    Hope this helps some what. Output for this will give you the temps, difference between temps and the average temps. As for the file output, don't know that much c++.

    Code:

    #include <iostream>
    using namespace std;

    int main() {
        double tempt, temp[12];

        cout << "Enter a temps:" << endl;

        //Get the temps.
        for (int i = 1; i <= 12; i++) {
            cin >> temp[i];
        }

        cout << temp[1] << endl;
        //Get the diff betweek the temps.
        for (int i = 2; i <= 12; i++) {
            cout << temp[i] << " " << temp[i] - temp[ i - 1] << endl;
        }

        //Get the sum of the Temps, and avarage it out.
        for (int i = 1; i <= 12; i++) {
            tempt += temp[i];
        }
        cout << "Avargae = " << tempt / 12 << endl;

        return 0;
    }


  • All times are GMT -7. The time now is 01:24 PM.