小编Mar*_*ini的帖子

在整数数组中对每个其他组件求和/添加失败

我继续寻求存储输入信用卡号并进行验证.

1)用户类型的hipothetic信用卡号码,如1234567898769999(存储为字符串).2)将字符串转换为整数数组int digits [].3)在位置1,3,5 ......最后奇数位置乘以2乘以数字位,例如2*2,2*4,2*6,2*8,2*8,2*6,2*9, 2*9.4)将它们存放在相同的阵列和位置[4,8,12,16,16,12,18,18].5)位置0,2,4 ......最后偶数位的和数.

尝试运行下面的代码,出现异常值:

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

int main (void) {
    string cc_string;

    printf("Please enter a credit card number:\n");

    //Capture credit card number
    cc_string = GetString();

    // Array of integers for credit card digits int cc_digits[15];
    int sum_evens, sum_odds = 0;

    for (int i = 0; i < 16; i++)
    {   
        cc_digits[i] = cc_string[i] - '0';

        //Sum digits in even positions (0 ... 14)
        if (i % 2 == 0)
        {
            sum_evens = …
Run Code Online (Sandbox Code Playgroud)

c arrays validation integer cs50

0
推荐指数
1
解决办法
59
查看次数

标签 统计

arrays ×1

c ×1

cs50 ×1

integer ×1

validation ×1