Galera, I'm a C-language beginner, I'm challenging and I'm packing in a part of the code.
#include <cs50.h>
#include <stdio.h>
long long n = get_long_long("Number: ");
char card_number[15];
sprintf(card_number, "%lld", n);
int length_number = strlen(card_number);
for(int i = 0; i < length_number; i++)
{
printf("A soma entre %c e %c é: %i \n", (int) card_number[i], (int)card_number[i], (int)(card_number[i] * 2));
}
printf("%s\n", card_number);
The get_long_long
method is from an external library, from CS50 to be more accurate. It saves in the variable what the user wrote at the prompt according to what was requested ( "Number: "
).
card_number[i]
equals two, at the time of multiplying it ends up understanding that 2 as 50 (2 in the ASCII table equals 50) and the result gives 100, when in fact it should give 4! I've tried it in many ways and nothing! Depending on the type of %
I put, it changes the value of the sum to a letter. I really want to figure it out and understand why.