C++计算总是打印出来的11

C++计算总是打印出来的11,c++,C++,我目前正在编写一个程序,根据用户输入的ISBN部分的数字,给用户一个校验和。我对13位国际标准书号的计算给了我正确的答案,但出于某种原因,对10位数字的计算总是给了我11,不管我输入了什么 cout << "Enter the digits one at a time, as if they were to be read from right to left." << endl; cin >> digit_one; cin >> digit_t

我目前正在编写一个程序,根据用户输入的ISBN部分的数字,给用户一个校验和。我对13位国际标准书号的计算给了我正确的答案,但出于某种原因,对10位数字的计算总是给了我11,不管我输入了什么

cout << "Enter the digits one at a time, as if they were to be read from right to left." << endl;

cin >> digit_one;
cin >> digit_two;
cin >> digit_three;
cin >> digit_four;
cin >> digit_five;
cin >> digit_six;
cin >> digit_seven;
cin >> digit_eight;
cin >> digit_nine;

checksum = (11 - (((10, 9, 8, 7, 6, 5, 4, 3, 2) * (digit_one, digit_two, digit_three, digit_four, digit_five, digit_six, digit_seven, digit_eight, digit_nine)) % 11));

cout << "The checksum for this ISBN is " << checksum << endl;

有什么简单的东西是我遗漏的吗?提前感谢您的帮助。

您似乎误解了操作员的工作原理。2,3生成3,而不是Python中的元组

同样的,2,3,4*1,2,3相当于4*3

那么,在你的代码中

checksum = (11 - (((10, 9, 8, 7, 6, 5, 4, 3, 2) * (digit_one, digit_two, digit_three, digit_four, digit_five, digit_six, digit_seven, digit_eight, digit_nine)) % 11))

checksum = (11 - ((2 * digit_nine) % 11)) 
然后可以安全地假设您的数字_九是0,这就是为什么最后校验和的值是11-0


1或11的乘法,而不是一个数字

逗号运算符并不像你想象的那样。对难以想象的我知道。10,9,8,7,6,5,4,3,2*数字1,数字2,数字3,数字4,数字5,数字6,数字7,数字8,数字9将编译,但它几乎是胡说八道,最重要的是它没有做你认为应该做的事情。非常感谢!事实证明,我认为13位ISBN校验和计算器能够工作的唯一原因是,它碰巧为我使用的示例给出了正确的答案。