gpt4 book ai didi

c++ - 为什么尽管我的函数和 cout 语句放置错误,但我的程序仍能运行?

转载 作者:搜寻专家 更新时间:2023-10-31 01:29:59 25 4
gpt4 key购买 nike

<分区>

理想情况下,我的 Fahrenheit 函数的一些内容应该放在 main 函数中但想尝试一下。我在 Fahrenheit 函数中请求用户输入,此后,我在 cout 语句之后调用了 Fahrenheit 函数。我希望首先显示“您的温度...”字符串,但它在继续打印字符串之前要求输入。为什么会这样?

#include <iostream>
using namespace std;
int FahrenheitConv();
int main ()
{
cout << "Your temperature in Fahrenheit is "<< FahrenheitConv();
return 0;
}

int FahrenheitConv()
{
double centigrade;
cout << "What is your temperature in centigrade: ";
cin >> centigrade;

double fahrenheit = (1.8) * (centigrade ) + 32;
return fahrenheit;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com