c++ - 期望从 while 循环中输出四个打印输出,只得到一个
问题描述
我正在尝试使用 while 循环编写一个程序,该循环根据声明的输入变量的范围给出输出。
#include <iostream>
using namespace std;
int main() {
float fahren = 0;
float celsius;
while (fahren < 400) {
// convert fahreneheit to celsius
// Subtract 32, then multiply it by 5, then divide by 9
celsius = 5 * (fahren - 32) / 9;
cout << celsius;
fahren+= 100;
}
return 0;
}
我希望返回 4 个值,但我只得到 1,即 0 处的值。
解决方案
您打印 4 个值但没有分隔符,您可以添加std::cout << std::endl;
while (fahren < 400) {
// convert fahreneheit to celsius
// Subtract 32, then multiply it by 5, then divide by 9
celsius = 5 * (fahren - 32) / 9;
std::cout << celsius << std::endl; // added new line here
fahren += 100;
}
推荐阅读
- wolfram-mathematica - 在 Mathematica 中通过引用传递列表元素
- sql - 加入内部和外部子查询
- c++ - C++ 和 Rust 之间的共享内存
- python - 如何用 discord bot python 警告某人
- java - 如何从字节 [] 打印十六进制?
- amazon-web-services - Amazon Linux 2 上的 Elastic Beanstalk、Django、Docker 平台 - 在 postdeploy 钩子不工作中运行 docker-compose exec
- facebook-graph-api - Facebook Graph API 返回组中事件的空数组 (GET /v11.0/{group-id}/events HTTP/1.1)
- microcontroller - 什么样的代码/指令可以使MCU以最大功耗运行
- python - 安装 cairosvg 和加载库时出错
- java - ArrayList 输出不断重复