Re: Airline ticket problem
You need to get the mod of the value of the ticket. Therefore in your first loop you need to convert the characters entered into the ticketno (an int)
Originally posted by CrackerJack Promise this is the last time I'm going to pick your guys brain for a while..:p
OK...the program is suppose to find out if a ticket number is valid or not. What happens is the last digit of number must match the remainder when the other digits - as a group - are divided by 7.
It then says at the bottom not to read the number in a single step, but to read the digits one-by-one w/ getchar.
Apprrantly I am doing something wrong though. Any advice?
printf("Enter ticket number: ");
while ( ( ch = getchar() ) != '\n' )
i = 7 % ch;
if ( (ch / count) == i )
printf("Not a valid ticket!");
But you also need to save the last number (ones digit) for the comparison, also converted from a char to an int. Figure out how to do that without loosing the value when the \n is read.
Then, after the input you do the calculating...
Oh, and no array is necessary...