它循环1-6并分配两个值,num1和NUM2。逻辑operation/if语句有问题,因为某种原因它在第一个地方不起作用。有人帮忙吗?
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 6; ++i){
int num1 = i;
int num2 = i;
if (num1 + num2 == 9){
cout << num1 << " + " << num2 << " = " << " 9 " << endl;
}
}
}
我还没试过,但我会试一下:
for (loop in your first dice){
for (loop in your second dice){
add the 2 numbers together;
if (the sum is equal to 9) {
cout << sum;
}
}
}
double for循环应该检查每个数字与第二个骰子的所有数字,并检查它们是否等于9。
编辑伪代码的更改代码
您应该使用双嵌套循环并检查每个骰子的值之和。
#include <iostream>
using namespace std;
int main()
{
int die[6] = {1, 2, 3, 4, 5, 6};
int die2[6] = {1, 2, 3, 4, 5, 6};
int i, x;
for (i = 0; i < 6; ++i){
for (x = 0; x < 6; ++x){
if (die[i] + die2[x] == 9){
cout << die[i] << ' ' << die2[x] << '\n';
}
}
}
}