-1
Guys, I’m a beginner in the C language, I’m doing a challenge.
#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 method get_long_long
is an external library, CS50 to be more exact. It stores in the variable what the user wrote in the prompt according to what was requested ("Number: "
).
Assuming that the card_number[i]
is equal to two, at the time of multiplying he ends up understanding this 2 as 50 (2 in the ASCII table is equal to 50) and the result gives 100, when in fact it should give 4! I tried several ways and nothing! Depending on the type of %
that I put, it changes the value of the sum to a letter. I really want to solve and understand why this.