Mega Search
23.2 Million


Sign Up

Make a donation  
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++

In article , 
no@email.provided says...

[ ... ]

> > Because the person who wrote the description was a moron, or perhaps
> > simply because he was trying to take a simple problem and turn it into
> > something more complex.
> 
> Or because he had in mind the algorithm he wanted the student to write,

You're probably right that he did have the algorithm in mind ahead of 
time -- but that doesn't justify the "Or" -- it merely demonstrates HOW 
he's a moron.  A challenge for a programming contest should NOT be 
written as something that's basically "guess what I've thought of".  It 
should be something that has a number of valid approaches, so that 
solving it demonstrates programming ability rather than the ability to 
guess what he happened to have in mind.

> and
> chose airline-ticket numbers of unspecified length as a _hypothetical_
> application for it. Further, by applying a little of the common sense and
> insight that one reasonably expects a competent computer science student to
> possess, he probably expected the student to understand what is required and
> not get hung up on real-world details that are clearly irrelevant to the
> stated problem.

Well, at least now you've shown your true colors -- as far as you care 
the "real world" is just a bunch of details we should "not get hung up 
on".

For better or worse, some of us work in the real world on a regular 
basis, and making things work well in the real world is what matters, 
not playing purely hypothetical games.

-- 
    Later,
    Jerry.

The universe is a figment of its own imagination.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 2:57 AM EST
From: Jerry Coffin
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
Oh for god's sake let's stop arguing with the idiot! He has his
fixed idea, he's not going to change his mind, he insists that the
problem creator is a moron. He's not going to be convinced by
anything we can say. "It is as useless to argue with those that have
renounced the use and authority of reason as to argue with the
dead."

-- 
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'gbzmlpu@cbobk.pbz' | rot13

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 3:10 AM EST
From: Tom Zych
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
Jerry Coffin wrote:

>> Update: I found an airline ticket lying around (from American Airlines,
>> if it matters). It has a fourteen-digit ticket number. Methinks the
>> length of ticket numbers may not be as granite-engraved as you are led to
>> believe.
> 
> Methinks if you honestly want us to believe that, you'd better be
> prepared to show some reason to believe it -- I have quite a few tickets
> around, from AA, UA, Pulkovo (a Russian Airline), Air France, Lufthansa,
> Delta, and absolutely EVERY one of them follows exactly the same format.
> 

FWIW, according to the following URL this company, which in some part is
involved in verifying airline tickets, has/suggests 14 digits, including
the check digit:

http://www.airauto.com/aai/about/newsletters/newsletters_2001_3.htm



-trey


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 11-Sep-2003, at 11:30 PM EST
From: trey
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
 Methinks the length of
>>
> 
> 
> Methinks if you honestly want us to believe that, you'd better be 
> prepared to show some reason to believe it -- I have quite a few tickets 
> around, from AA, UA, Pulkovo (a Russian Airline), Air France, Lufthansa, 
> Delta, and absolutely EVERY one of them follows exactly the same format. 
> 


Methinks that we all like to think we always have the right answer.
A truly enlightened person would be willing to consider that there is
more to the world than the small part we do know.


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 3:36 AM EST
From: SomeDumbGuy
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
SomeDumbGuy wrote:

> 
> 
> Methinks that we all like to think we always have the right answer.
> A truly enlightened person would be willing to consider that there is
> more to the world than the small part we do know.
> 

Ah Great - next someone is going to start spoting poetry :-[


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 11-Sep-2003, at 8:49 PM EST
From: James Connell
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++

James Connell wrote:
> SomeDumbGuy wrote:
> 
>>
>>
>> Methinks that we all like to think we always have the right answer.
>> A truly enlightened person would be willing to consider that there is
>> more to the world than the small part we do know.
>>
> 
> Ah Great - next someone is going to start spoting poetry :-[
> 


Ya, I canceled it but I guess you got it first.  I think my horse was a 
little too high today :)


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 5:06 AM EST
From: SomeDumbGuy
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
Jerry Coffin  wrote in message
news:MPG.19cadb1a41331ca19896b9@news.west.earthlink.net...
> In article ,
> no@email.provided says...
>
> [ ... ]
>
> > > Because the person who wrote the description was a moron, or perhaps
> > > simply because he was trying to take a simple problem and turn it into
> > > something more complex.
> >
> > Or because he had in mind the algorithm he wanted the student to write,
>
> You're probably right that he did have the algorithm in mind ahead of
> time -- but that doesn't justify the "Or" -- it merely demonstrates HOW
> he's a moron.  A challenge for a programming contest should NOT be
> written as something that's basically "guess what I've thought of".  It
> should be something that has a number of valid approaches, so that
> solving it demonstrates programming ability rather than the ability to
> guess what he happened to have in mind.

No "guessing" is required. Just read the question and do what it says.

> > and
> > chose airline-ticket numbers of unspecified length as a _hypothetical_
> > application for it. Further, by applying a little of the common sense
and
> > insight that one reasonably expects a competent computer science student
to
> > possess, he probably expected the student to understand what is required
and
> > not get hung up on real-world details that are clearly irrelevant to the
> > stated problem.
>
> Well, at least now you've shown your true colors -- as far as you care
> the "real world" is just a bunch of details we should "not get hung up
> on".

For the purpose of such a question in an exam, quite _clearly_ the
real-world details of airline tickets are irrelevant. The student is working
for a degree in _computer science_, not for a job as an airline hostess.

> For better or worse, some of us work in the real world on a regular
> basis, and making things work well in the real world is what matters,
> not playing purely hypothetical games.

Junior school exam question:
Q. If a train takes two minutes to travel three miles, how long will it take
to travel 150 miles?
A. 100 minutes.
Jerry's answer: That depends on many factors. If the train burns a fossil
fuel then you need to take into account the steady loss of mass by the train
as the fuel is consumed. Then there are the effects of the thermal expansion
of the different metals in the engine, transmission and wheels. Countering
the thermal expansion of the wheels, however, is the steady wear of the
wheels on the tracks, which reduces their circumference slightly, and also
their mass. The shifting weight of passengers within the train will also
subject wheel bearings to forces that will...

[much later]

And then there are the relativistic effects. If the clock at the origin and
the clock three miles away were synchronized by a light flash from the...

....and by applying the Lorentz transformation we see that the vibrations due
to the train's whistle...

DW




Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 3:27 PM EST
From: David White
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
On Tue, 09 Sep 2003 21:41:52 -0500, Bill Reed  wrote:

>I am totally confused on this one. I've reviewed the material that
>pertains to this exercise a number of times. I don't even know where
>to start. The code below is basically my pathetic thoughts as
>expressed through the keyboard. If anyone can get me back on my feet I
>would be very grateful. Oh, BTW, does anyone have a kleenex?
>
>/* 
>Airline tickets are assigned lengthy identifying numbers, such as
>47715497443. To be valid, the last digit of the number must match 
>the remainder when the other digits--as a group--are divided by 
>7. (For example, 4771549744 divided by 7 yields a remainder of 3.) 
>Write a program that checks whether or not an airline ticket 
>number is valid:
>
>Enter ticket number: 47715497443
>VALID
>
>Hint: Don't attempt to read the number in a single step. Instead, 
>use getchar to obtain its digits one by one. Carry out the 
>division on its digits one at a time, being careful not to include 
>the last digit in the division.
>*/
>
>#include 
>
>int main(void)
>{
>  char ch;
>  int digits = 0;
>  int check;
>  
>  printf("Enter ticket number: ");
>  while ((ch = getchar()) != '\n') {
>	  //printf("%c", ch);
>    check += ch % 7;
>    digits++;
>  }
>  //printf("%c", check);
>  if (check == digits-1)
>    printf("VALID\n");
>    
>  return 0;
>}
>
>Thanks,
>Bill


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 5:46 AM EST
From: Bill Reed
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
Bill Reed  wrote in message news:...
 
> I am totally confused on this one. I've reviewed the material that
> pertains to this exercise a number of times. I don't even know where
> to start. The code below is basically my pathetic thoughts as
> expressed through the keyboard. If anyone can get me back on my feet I
> would be very grateful. 
 
Hi,
I'm studying the C programming language on my own, at home, using the
same book (C Programming: A Modern Approach, by K. N. King).
 
This is my answer to this exercise (it's not needed to have both digit
and ch, but I used them for clarity):
 
/*
 * By Quique, September 2003
 */

#include 

int
main ()
{
    char ch;
    int digit;
    int dividend;
    int remainder = 0;

    printf ("Enter ticket number: ");

    while ((ch = getchar ()) != '\n')
    {
        /* 1 is 49 in ASCII, and 0 is 48. 49 - 48 = 1 :-) */
        digit = ch - '0'; 

        dividend = remainder * 10 + digit;
        if (dividend >= 7)
            remainder = dividend % 7;
        else
            remainder = dividend;
    }

    /* We recover the reminder before using the check digit */
    remainder = (dividend - digit) / 10;

    if (remainder == digit)
        printf ("VALID\n");
    else
        printf ("INVALID\n");

    return 0;
}
 
 
And this is a solution that was posted here a few years ago:
 
/* 
 * By Ed Hook (hook@cscsun2.larc.nasa.gov), August 1997
 */

#include 

int main(void)
{
    int previous = 0;
    int current;
    int digit1;
    int digit2;
    
    /* prime the pump */
    digit1 = getchar();
    digit1 -= '0';
    current = digit1;
    
    while ((digit2 = getchar()) != '\n' ) 
    {
        digit2 -= '0';
        previous = (10 * previous + digit1) % 7;
        current  = (10 * previous + digit2) % 7;
        digit1 = digit2;
    }       
    
    digit1 %= 7;    /* final digit mod 7 is the check value */
    if ( previous == digit1 )
        printf("valid\n");
    else
        printf("invalid\n");
        
    return 0;
}      
 
Hope that helps,
 Quique

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 6:06 AM EST
From: Quique
 
Re: [C] Reading and arithmetic with getchar()  
News Group: alt.comp.lang.learn.c-c++
SomeDumbGuy wrote:
> 
> 
> James Connell wrote:
> 
>> SomeDumbGuy wrote:
>>
>>>
>>>
>>> Methinks that we all like to think we always have the right answer.
>>> A truly enlightened person would be willing to consider that there is
>>> more to the world than the small part we do know.
>>>
>>
>> Ah Great - next someone is going to start spoting poetry :-[
>>
> 
> 
> Ya, I canceled it but I guess you got it first.  I think my horse was a 
> little too high today :)
> 
nothing wrong with the sentiment - just sounds to much like "confusous 
say" ;)
only problem with a high horse is the fall.


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Sep-2003, at 5:14 AM EST
From: James Connell