A file is required to record the daily temperatures of a city for one week from Monday to
Sunday. Write a C/C++ program to enter the daily temperatures along with the name of the
day, read the file, compute the average temperature for the week and display it. The final
output of the program should be as follows.
Monday 31
Tuesday 32
Wednesday 33
Thursday 36
Friday 32
Saturday 31
Sunday 32
Average Temperature:- 32.4

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
    string str; int tmp; double sum = 0;
    ifstream ifs("file.txt");
    while(ifs>>str>>tmp){
        cout << str << ' ' << tmp << endl;
        sum += tmp;
    }
    cout << "Average Temperature:" << sum/7 << endl;
}

What did YOU tried?

commented: thank you so much. why use "file.txt" for this.how help it for this programme. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.