【发布时间】:2015-10-08 01:30:36
【问题描述】:
一个交互式 C++ 程序,其输入是来自用户的一系列 12 个温度。它应该在文件 tempdata.dat 上写出每个温度以及当前温度与其前一个温度之间的差异。对于输入的第一个温度,不输出差值。在程序结束时,应通过 cout 为用户显示平均温度。
这是我目前所拥有的:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int counter = 0;
int previousTemp;
ofstream file; //declares a file of type ofstream
file.open("temperaturefile.txt"); //opens the file with open method
int temperature = 0;
int difference = 0;
cout << "Enter 12 temperatutes" << endl;
file << temperature;
while (counter < 12)
{
cin >> temperature;
counter++;
// difference = temperature-previousTemp;
// cout << difference << endl;
//
}
}
【问题讨论】:
-
然后呢?您还没有提出实际问题。
-
我更新了程序。抱歉,我还是堆栈溢出的新手