Help With Simple Summation...

This is a discussion on Help With Simple Summation... within the C Programming forums, part of the General Programming Boards category; Originally Posted by quzah What are you talking about? Rather, who are you talking about? That's what the 'quote' button ...

  1. #16
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Quote Originally Posted by quzah
    What are you talking about? Rather, who are you talking about? That's what the 'quote' button is for. Mine works fine. It even does negatives; I know, I tested it.


    Quzah.
    Good to see that I'm not the only one confused by this.

    >>And how do you propose we handle situations were a person wants to sum up say like:
    12 and 15? Your solution breaks down.

    This is immaterial - If I'm not mistaken (and I stand to be corrected by the OP if I am), the
    task is to enter a sequence of digits and add all the individual digits entered up - last I checked,
    in the base 10 number system, 12 and 15 are not single digits. Basically I think that your
    interpretation of the task is to enter a certain amount of numbers (note, not digits) and add
    them all up. I don't think that this is the case, and apparently neither does quzah. Quzah's
    solution solves his interpretation of the task just fine.

    This whole thing could be avoided if the OP had expressed his question more clearly.

    A couple more things:

    1: >>The wrong number. Ie, undefined behavior.

    I think you need to look up your definition of undefined behavior - such as using atoi without
    including the correct header - that's undefined, getting the "wrong number" isn't specifically

    2: It's never a good idea to challenge "certain" people on this forum (in this case, quzah),
    unless you're on rock solid ground - it just doesn't end pretty. Just because you mightn't see
    his code lying around here that often, doesn't mean he's not right when he points out people's
    mistakes either. Quzah - you either love him or hate him
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by cdalten
    Q, I could be a real dick and say ask your local college for a refund, but a demo from my computer is enough.
    There is no "demo" from your computer, because you didn't do what you imply you did. You're lying to try and make your point.
    Quote Originally Posted by cdalten
    now I try 12 and 15
    $./sumit
    1215

    9$

    The wrong number. Ie, undefined behavior.
    It's not undefined behavior. You entered one number. Let me teach you a little bit about basic base-10 math. Then you might want to call your elementry school and ask for some classes.

    Here we have the concept of a digit. A digit is a single character, in base ten, ranging from 0 to 9. The digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Zero (0) is the smallest, and is usually used to represent "nothing". 9 is the largest, and is used to represent ... nine. Count on your fingers if you need to. Here's a hint, it's all of your fingers, including thumbs, minus one. I know, that was a bit unfair of me, since I haven't gone into subtraction yet. But play along.

    Now, what happens when we have more than nine? You know, like all your fingers, plus both thumbs. Well then we have another digit. This digit goes beside the first, to the left of it. As we increase in digits, each one gets placed to the left. Each digit represents a pile of the maximum digit of the previous field, plus one. That is to say:

    10

    Represents nine + 1.

    Then you start incrementing (that is to add, or increase by one) the right hand digit one at a time, until it reaches nine again, at which point you reset it to zero, and increment the one digit to the left of that by one. If ever you run out of left most digits, you just add one more on top of that.

    We'll ignore decimals for now, because I don't think you're up to it.

    Anyway, what does this all have to do with you? Ah, here we go:
    Quote Originally Posted by cdalten
    now I try 12 and 15
    $./sumit
    1215

    9$

    The wrong number. Ie, undefined behavior.
    See, you didn't enter "12 and 15", you entered a single four digit number. Remember above where I said if they're all side by side it counts as a single number with multiple digits? Yeah, that's what you did. Oh! Just like the OP's original example! See, they didn't enter "12" and "34" and "5". They didn't enter "1" and "23" and "45". They didn't enter "1" and "2" and 34" and "5", or any other combination of more than one number. No, that counts as a single five digit number. You know, like they said they wanted.

    Therefore, we deduct, you know, with basic mathematics, that you didn't in fact enter 12 and 15, you instead entered "1215", which summed up gives you nine. Holy ........! It is the right number after all!

    You really should look into that elementry school thing.


    Quzah.
    Last edited by quzah; 08-09-2006 at 01:07 AM. Reason: I can spell original more ways than anyone I know.
    Hope is the first step on the road to disappointment.

  3. #18
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Quzah: 1
    Opponent: 0

    How the [insert profanity here] do you know Quzah hasn't had anything to his name? What if he's all of the lead GCC developer? What if he's Bjarne in hiding?

    And looky here, he's posted a 1-1/2 page elementary-school lesson for a person who insults him in public. You brashly attacked the poster, not the post by insulting Quzah personally and no matter how wrong he was (if he was wrong) about the code you have actually breached netiquette.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  4. #19
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    Quzah's rebuttals are better than anyone else's on this board, but just for the record he was never wrong. I suppose it's just that other people refused to understand his advice. While I could speak volumes about how retarded that is, the thread is over.

    How do I sage?
    Last edited by whiteflags; 08-09-2006 at 10:00 AM.

  5. #20
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    It's not going anywhere, and the OP can't be bothered to contribute to their own thread - closed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 06:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 06:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21