Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1521|回复: 5
打印 上一主题 下一主题

c++ 求救

[复制链接]

26

主题

2

好友

365

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

跳转到指定楼层
1#
发表于 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




收藏收藏0

5

主题

0

好友

1091

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

2#
发表于 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;


回复

使用道具 举报

26

主题

2

好友

365

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

3#
发表于 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


回复

使用道具 举报

5

主题

0

好友

1091

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

4#
发表于 2012-9-18 10:11 PM |只看该作者
你这题目,谁知道你的 valid 是怎样的判断法 。 。 。


回复

使用道具 举报

26

主题

2

好友

365

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

5#
发表于 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


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

6#
发表于 2012-9-19 10:50 PM |只看该作者
实在是没耐心看完。
我可以贡献你的只是顶贴。

加油


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-26 02:33 PM , Processed in 0.118896 second(s), 27 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部