C++ 控制台在立即获得输入后立即退出 #包括 #包括 #包括 #包括 #包括 使用名称空间std; int杀死; 死亡人数; int main() { 杀戮; 死亡; 浮动答案=死亡/死亡; cout

C++ 控制台在立即获得输入后立即退出 #包括 #包括 #包括 #包括 #包括 使用名称空间std; int杀死; 死亡人数; int main() { 杀戮; 死亡; 浮动答案=死亡/死亡; cout,c++,console,fstream,C++,Console,Fstream,请将下面的语句放在return语句之前 #include <cstdlib> #include <crime> #include <stream> #include <cmath> #include <iostream> using namespace std; int Kills; int Deaths; int main() { cout << "Please Enter The Amount Of Kills Y

请将下面的语句放在return语句之前

#include <cstdlib>
#include <crime>
#include <stream>
#include <cmath>
#include <iostream>

using namespace std;
int Kills;
int Deaths;


int main()
{
cout << "Please Enter The Amount Of Kills You Have: ";
cin >> Kills;
cout << "Please Enter The Amount Of Deaths You Have: ";
cin >> Deaths;

float answer = Kills / Deaths;

cout << "Your KD Is: " << answer;
//creating a .txt file 
ofstream pctalk;
pctalk.open("KDA Tracker.txt", ios::app);

//actually logging
pctalk << "Kills: " << Kills << " | " << "Deaths: " << Deaths << " | " << "KD Ratio:  " << answer << 
"\n";
//closing our file
pctalk.close();
return 0;
}

这是一个可怕的、完全依赖于系统的黑客。这是一个不应该被教的坏习惯。一个更好的解决方案和更多的C++惯用方法是<代码>:ST::CIN。提示?这是Visual Studio特有的东西,当你运行你的程序时,否则你真的希望你的程序停止并请求输入的地方很少。如果你真的想要它,你可以很容易地自己实现它,只需提问,然后扔掉。与你的问题无关,但这一行
float-answer=Kills/Deaths;
不太可能做你想做的事。
Kills
death
都是
int
,在整数数学中9/12是0。你可能想要分数答案,所以需要在那里进行转换;例如:
float answer=static\u cast(Kills)/Deaths;
非常接近,尽管它不能解释这种行为。我相信有一个问题确实存在。
system("pause");