无论 cin 是什么,它都会继续输出 0 的分数。这是为什么?我尝试返回“return 0;”但还是不行:/
#include "stdafx.h"
#include <iostream>
using namespace std;
// Variables
int enemiesKilled;
const int KILLS = 150;
int score = enemiesKilled * KILLS;
int main()
{
cout << "How many enemies did you kill?" << endl;
cin >> enemiesKilled;
cout << "Your score: " << score << endl;
return 0;
}
最佳答案
您需要在用户输入后执行乘法:
int main()
{
cout << "How many enemies did you kill?" << endl;
cin >> enemiesKilled;
int score = enemiesKilled * KILLS;
cout << "Your score: " << score << endl;
return 0;
}
在线查看:ideone
关于无论用户输入什么,C++ cin 都会为整数返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13912628/