gpt4 book ai didi

CS50学分任务回顾

转载 作者:行者123 更新时间:2023-11-30 20:57:30 24 4
gpt4 key购买 nike

我有一个非常有趣的案例。我已经编写了已编译的源代码,并且可以正常工作,但是当我将代码添加到类(class)中以供审核时,出现了下一个问题:

:) credit.c exists.

:) credit.c compiles.

:( identifies 378282246310005 as AMEX expected "AMEX\n", not "\nAMEX\n"

:( identifies 371449635398431 as AMEX expected "AMEX\n", not "\nAMEX\n"

:( identifies 5555555555554444 as MASTERCARD
expected "MASTERCARD\n", not "\nMASTERCARD\n"

:) identifies 5105105105105100 as MASTERCARD

:) identifies 4111111111111111 as VISA

:( identifies 4012888888881881 as VISA
expected "VISA\n", not "\nVISA\n"

:( identifies 1234567890 as INVALID
expected "INVALID\n", not "\nINVALID\n"

:) identifies 369421438430814 as INVALID

:( identifies 4062901840 as INVALID
expected exit code 0, not 1

:) identifies 5673598276138003 as INVALID

:( identifies 4111111111111113 as INVALID
expected exit code 0, not 1

:) rejects a non-numeric input of "foo"

:) rejects a non-numeric input of ""

下一部分是我的代码:

#include <stdio.h>
#include <cs50.h>
#include <math.h>

int main (void)
{
long long card_num;


// getting card number
do
{
card_num = get_long("Number: \n");
}
while (card_num < 1 || card_num > 9999999999999999);

for (int i = 0; i < card_num.length(); i++)
{
if (card_num[i] == '-')
printf('foo\n');
card_num[i] == '';
else (card_num[i] == ' ')
printf ('foo\n');
card_num[i] == '';
}

long long temp_num = card_num;

int count = 0;

while (temp_num > 0)
{
temp_num = temp_num / 10;
count++;
}


// umber volume cheking
if (count != 13 && count != 15 && count != 16)
{
printf("INVALID\n");
return 1;
}

// luna's algorithm checking
int sum = 0;
temp_num = card_num;
for (int i = 1; i <= count; i++)
{
int digit = temp_num % 10;
if (i % 2 == 0)
{
digit *= 2;
if (digit > 9)
{
digit -= 9;
}
}

sum += digit;
temp_num /= 10;
}

if (sum % 10 != 0)
{
printf("INVALID\n");
return 1;
}

// bank info cheking
temp_num = card_num;
while (temp_num > 100)
{
temp_num = temp_num / 10;
}

int company_id = temp_num;
if (company_id > 50 && company_id < 56 && count == 16)
{
printf("MASTERCARD\n");
}
else if ((company_id == 34 || company_id == 37) && (count == 15))
{
printf("AMEX\n");
}
else if ((company_id / 10 == 4) && (count == 13 || count == 16))
{
printf("VISA\n");
}
else
{
printf("INVALID\n");
}
return 0;
}

最佳答案

好消息! CS50有自己的SE社区,你可以找到here .

密切注意错误告诉您的内容。某处输出了一个额外的回车符 (\n),如下所示: :( 将 378282246310005 标识为 AMEX 预期的“AMEX\n”,而不是“\nAMEX\n”。请注意 check50 期望的内容 ("AMEX\n") 和程序输出的内容 ("\nAMEX\n") 之间的差异。纠正后它将消除 5 个错误。好的开始。

检查代码以查看其返回退出代码 1 的位置。规范不要求这样做。遵守规范。有时并不是越多越好:)。纠正后,将消除最后两个错误。

也许这些看起来像是小细节,不应该影响评分。但如果老板或客户希望严格遵守规范,这些“小细节”就可以转化为真正的金钱。

关于CS50学分任务回顾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58839140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com