|登录 |注册

查看: 1776|回复: 5
打印 上一主题 下一主题

c++ 求救

[复制链接]
天空上白云
2012-9-18 05:11 PM
‎#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 |联系我们 |隐私政策 |Share

GMT+8, 2026-1-1 03:48 AM , Processed in 0.107064 second(s), 26 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部