我怎么让程序减去之前的温度和当前的温度
How would I make program subtract the previous temp and current temp
一个交互式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;
//
}
}
您在代码中注释了它吗?我不明白
difference = temperature-previousTemp;
可以在循环结束时跟踪previousTemp。在循环中的所有内容之后放入
previousTemp=temperature;
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 基于boost的程序的静态链接——zlib问题
- 循环通过网格获取温度,但不知道如何告诉程序停止循环
- 处理温度程序
- 温度转换程序c++
- 我怎么让程序减去之前的温度和当前的温度