无论是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;
}
答案 0 :(得分:4)
您需要在用户输入输入后执行乘法运算:
int main()
{
cout << "How many enemies did you kill?" << endl;
cin >> enemiesKilled;
int score = enemiesKilled * KILLS;
cout << "Your score: " << score << endl;
return 0;
}
在线查看:ideone
答案 1 :(得分:1)
您需要在用户输入号码后重新计算score
。
答案 2 :(得分:1)
cin >> enemiesKilled;
score = enemiesKilled * KILLS; // <-- Put the calculation here!!
cout << "Your score: " << score << endl;
答案 3 :(得分:1)
int enemiesKilled;
初始化为0.
int score = enemiesKilled * KILLS;
同时计算。由于enemiesKilled
为0,因此它也为0.
如其他答案中所述,您需要在运行时计算score
。