So say that I have the number 1234567 taken from the user with scanf. How can I store EACH DIGIT of this number into its own cell in an array? My code is as below, and I wanna modify it so that you can enter your SIN number on one line, not number by number.
Code:
/*
Fred Liu's SIN number validation program.
ICS3M Mr. Creelman period 2
Tuesday October 10, 2006 9:38 PM
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int sin[9], i;
printf("Welcome to Fred's program.\n\nPlease enter your SIN number one by one: ");
for (i = 0; i < 9; i++) // This and the next line stores The SIN # into integer array sin[9]
scanf("%d", &sin[i]);
for (i = 1; i < 8; i+=2) {
sin[i]*=2; // The 2nd, 4th, 6th, and 8th digits times 2
if (sin[i] > 9) // Minus 9 if greater than 9
sin[i]-=9;
}
if ((sin[1] + sin[3] + sin[5] + sin[7] + sin[0] + sin[2] + sin[4] + sin[6] + sin[8]) % 10 == 0) // This is steps b-e
printf("This SIN number is valid.");
else
printf("This is a fake SIN number. The government SWAT team has now been dispatched.");
printf("\n\n");
system("pause");
return(0);
}