如何将cout的输出存储到变量中 我正在制作一个C++程序,根据你的父母估计你的身高。我想让它,所以我可以输出的高度在英尺和英寸。我不知道如何将cout的输出存储在 if (boygirl == "boy") { cout <<"Your estimated height is " << (mom *13/12 + dad) / 2 << " inches"; } and else if (boygirl == "girl") { cout <<"Your estimated height is " << (dad+12/13 + mom) / 2 <<" inches"; if(boygirl==“boy”){ cout
你在找这样的东西吗:如何将cout的输出存储到变量中 我正在制作一个C++程序,根据你的父母估计你的身高。我想让它,所以我可以输出的高度在英尺和英寸。我不知道如何将cout的输出存储在 if (boygirl == "boy") { cout <<"Your estimated height is " << (mom *13/12 + dad) / 2 << " inches"; } and else if (boygirl == "girl") { cout <<"Your estimated height is " << (dad+12/13 + mom) / 2 <<" inches"; if(boygirl==“boy”){ cout,c++,output,cout,C++,Output,Cout,你在找这样的东西吗: int htInches = 0; if (boygirl == "boy") { htInches = (mom * 13 / 12 + dad) / 2; } else if (boygirl == "girl") { htInches = (dad + 12 / 13 + mom) / 2; } cout << "Your estimated height is " << ht
int htInches = 0;
if (boygirl == "boy") {
htInches = (mom * 13 / 12 + dad) / 2;
} else if (boygirl == "girl") {
htInches = (dad + 12 / 13 + mom) / 2;
}
cout << "Your estimated height is " << htInches << " inches";
int-htInches=0;
如果(男孩女孩=“男孩”){
htInches=(妈妈*13/12+爸爸)/2;
}否则如果(男孩女孩=“女孩”){
htInches=(爸爸+12/13+妈妈)/2;
}
您是否应该先将结果存储在变量中,然后在您的cout中使用它(变量)。而不是使用int-htInches;cout>htInches;我希望使用变量中的数据并将其应用于Covert(输出);我想保留英寸,但在我的代码中,我这样做了,这样我也可以以英尺为单位打印结果。我不知道如何删除要求他们从英寸中获得结果的部分。我想编辑我的代码,这样我就可以自动存储以前的结果,并将其插入转换函数,而无需用户输入。在我的示例中例如,您有他们得到的英寸结果,分配给名为htInches
的变量。您觉得这在何种程度上不能满足您的需要?我还需要以英尺为单位的结果。不仅仅是英寸调用Convert(htInches)
,就像您已经做的那样。只需删除cin>>htInches;
部分(和前面的提示)。我无法理解困难的本质。我正在尝试删除用户输入,以便可以看到这样的情况
int htInches = 0;
if (boygirl == "boy") {
htInches = (mom * 13 / 12 + dad) / 2;
} else if (boygirl == "girl") {
htInches = (dad + 12 / 13 + mom) / 2;
}
cout << "Your estimated height is " << htInches << " inches";