JBTALKS.CC

标题: c++ 求救 [打印本页]

作者: 天空上白云    时间: 2012-9-18 05:11 PM
标题: c++ 求救
‎#include <iostream>
using namespace std;

int main()

{

int p1, p2, p, ccnumber, number1, number2,ccnumber1, i;
p1=p2=p=ccnumber=0;


cout<<"Enter Credit Card Number: \n";
cin>>ccnumber1;

for( i=1;i<=8;i++)
{
ccnumber1=ccnumber1/10;
number1=ccnumber1%10;
number1=number1*2;

if (number1 > 9)
number1=number1-9;
p1= p1 + number1;
ccnumber1=ccnumber1/10;
number2=ccnumber1%10;
p2=p2+ number2;
};

p=p1+p2;
ccnumber=10-(p%10);


if (ccnumber==5)
cout<<"Your creditcard is valid\n";
else
cout<<"Your creditcard is not valid\n";


return 0;

}
学校credit card number check project

做么第二和第三会not valid..
哪里错。。

43589795
38994323
58721645
作者: L_Kuan    时间: 2012-9-18 06:19 PM
if 後少了{}?
if (number1 > 9)
number1=number1-9;
p1= p1 + number1;
ccnumber1=ccnumber1/10;
number2=ccnumber1%10;

沒給問題,誰知道你到底要寫怎樣的邏輯
p2=p2+ number2;
作者: 天空上白云    时间: 2012-9-18 06:41 PM
if 後少了{}?
if (number1 > 9)
number1=number1-9;
p1= p1 + number1;
ccnumber1=ccnumber1/10;
numb ...
L_Kuan 发表于 2012-9-18 06:19 PM



题目是
write a c++ program that implements this algorithm, this user should supply an 8-digit number, and you should print out whether the number is valid or not .if is not valid, you should print out the value of the check digit that would make the number valid
作者: L_Kuan    时间: 2012-9-18 10:11 PM
你这题目,谁知道你的 valid 是怎样的判断法 。 。 。
作者: 天空上白云    时间: 2012-9-19 08:42 AM
本帖最后由 天空上白云 于 2012-9-19 02:15 PM 编辑
你这题目,谁知道你的 valid 是怎样的判断法 。 。 。
L_Kuan 发表于 2012-9-18 10:11 PM


.starting from the right most digit, form the sum of every other digit. for example, if the credit card number is 4358 9795, then you form the sum 5+7+8+3 =23

.double each of the digits that were not included in the preceding step. add all digit of the resulting numbers. for example. with the number given above , doubling the digits, starting with the to last one, yield 18 18 10 8 . add all digits in these values 1+8+1+8+1+0+8 =27

。add the sums of two preceding steps. if the last digit of the results is 0, the number is valid. in our case, 23+72=50 , so the number is valid

write a c++ program that implements this algorithm. the user should supply 8-digit number, and you should print out wheter the number valid or not . if is not valid , you should print out the value of the check digit that would make the number valid .

答案0 要valid

和最后号码一样也要
例如
6261251”1“

答案“1” 也是valid
作者: 宅男-兜着走    时间: 2012-9-19 10:50 PM
实在是没耐心看完。
我可以贡献你的只是顶贴。

加油




欢迎光临 JBTALKS.CC (https://jbtalks.my/) Powered by Discuz! X2.5