Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #70229

Re: A finalized program

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: A finalized program
Date 2015-09-11 10:10 +0000
Organization Freie Universitaet Berlin
Message-ID <d5fnleFakjoU1@mid.uni-berlin.de> (permalink)
References <d93ca264-e41a-4f82-8c09-cd87731b2eed@googlegroups.com> <d586scFdva0U1@mid.uni-berlin.de> <2e6deec0-c080-41f5-8f1c-18d27e46621f@googlegroups.com> <d5ef25F1jopU1@mid.uni-berlin.de> <40035db3-80b7-4e3c-9855-fc7390d7a678@googlegroups.com>

Show all headers | View raw


Alla _ <modelling.data@gmail.com> wrote:
> After I have added this test, the part that checks for 
> letters and other than digits characters does work, but
> all the rest doesn't. 
> The program without this test part shows correct results
> in detecting the card issuer. When test is added, the main
> part stops working correctly: when I enter a valid card
> number, the program doesn't give any answer; when I then 
> enter any letter, it does produce the very last statement
> "Invalid" or nada :)
> ex: 

> Please, enter your card number:  
> 378282246310005
> q
> INVALID

> another ex:
> Please, enter your card number:  
> 378282246310005
> f

> Here is the program:

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

> int main(void)
> {
>     char card_number[17];
>     int i, number, digit, sum;
>     int sum1 = 0, sum2 = 0, sum3 = 0;
>     
>     printf ("Please, enter your card number:  \n");
>     
>     while (!(scanf ("%16[0-9]", card_number) == 1 && getchar() == '\n'))
>     {
>         printf ("This is not a card number; please, try again\n");
>         while (getchar() != '\n');
>     }
>     
>     if (scanf ("%16[0-9]", card_number) == 1)

You already have read in the card number in the while loop
(which tested if it was a proper number at all) but you now
ask for it again (without even prompting the user), so it's
not that much of a surprise that it doesn't seem to work
anymore if you don't enter the number a second time;-) Re-
move that line and see what happens.

                        Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-08 04:13 -0700
  Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-08 04:19 -0700
    Re: A finalized program fir <profesor.fir@gmail.com> - 2015-09-08 04:30 -0700
    Re: A finalized program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-08 14:45 +0100
      Re: A finalized program Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-08 08:29 -0700
      Re: A finalized program Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-08 08:52 -0700
        Re: A finalized program Martin Shobe <martin.shobe@yahoo.com> - 2015-09-08 13:01 -0500
        Re: A finalized program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-08 21:00 +0100
          Re: A finalized program Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-08 13:33 -0700
            Re: A finalized program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-09 00:28 +0100
  Re: A finalized program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-08 14:26 +0100
    Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-08 06:42 -0700
      Re: A finalized program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-08 20:50 +0100
        Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 01:47 -0700
  Re: A finalized program jt@toerring.de (Jens Thoms Toerring) - 2015-09-08 13:41 +0000
    Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-10 01:31 -0700
      Re: A finalized program jt@toerring.de (Jens Thoms Toerring) - 2015-09-10 10:39 +0000
        Re: A finalized program David Thompson <dave.thompson2@verizon.net> - 2015-09-20 18:35 -0400
    Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-10 01:33 -0700
    Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-10 10:16 -0700
      Re: A finalized program bartekltg <bartekltg@gmail.com> - 2015-09-10 20:08 +0200
        Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:05 -0700
          Re: A finalized program Richard Heathfield <rjh@cpax.org.uk> - 2015-09-11 10:17 +0100
            Re: A finalized program Richard Heathfield <rjh@cpax.org.uk> - 2015-09-11 10:19 +0100
            Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:28 -0700
            Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:29 -0700
        Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:19 -0700
          Re: A finalized program Richard Heathfield <rjh@cpax.org.uk> - 2015-09-11 10:23 +0100
            Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:33 -0700
              Re: A finalized program Keith Thompson <kst-u@mib.org> - 2015-09-11 14:11 -0700
                Re: A finalized program jt@toerring.de (Jens Thoms Toerring) - 2015-09-11 21:39 +0000
          Re: A finalized program bartekltg <bartekltg@gmail.com> - 2015-09-11 12:49 +0200
      Re: A finalized program Richard Heathfield <rjh@cpax.org.uk> - 2015-09-10 23:31 +0100
        Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:15 -0700
      Re: A finalized program jt@toerring.de (Jens Thoms Toerring) - 2015-09-10 22:37 +0000
        Re: A finalized program Richard Heathfield <rjh@cpax.org.uk> - 2015-09-10 23:47 +0100
          Re: A finalized program jt@toerring.de (Jens Thoms Toerring) - 2015-09-11 10:18 +0000
        Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 01:07 -0700
        Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 02:14 -0700
          Re: A finalized program jt@toerring.de (Jens Thoms Toerring) - 2015-09-11 10:10 +0000
            Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 04:19 -0700
  Re: A finalized program Barry Schwarz <schwarzb@dqel.com> - 2015-09-08 15:53 -0700
  Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 04:27 -0700
    Re: A finalized program bartekltg <bartekltg@gmail.com> - 2015-09-11 14:05 +0200
  Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 04:42 -0700
    Re: A finalized program bartekltg <bartekltg@gmail.com> - 2015-09-11 14:15 +0200
      Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 05:50 -0700
        Re: A finalized program bartekltg <bartekltg@gmail.com> - 2015-09-11 15:00 +0200
      Re: A finalized program Alla _ <modelling.data@gmail.com> - 2015-09-11 05:50 -0700
    Re: A finalized program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-11 13:46 +0100
      Re: A finalized program Richard Heathfield <rjh@cpax.org.uk> - 2015-09-11 14:19 +0100

csiph-web