problem with program!!

Discussion in 'Programming General' started by jman007_93, Feb 8, 2008.

problem with program!!
  1. Unread #1 - Feb 8, 2008 at 11:29 PM
  2. jman007_93
    Joined:
    Jan 7, 2008
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    jman007_93 Member

    problem with program!!

    hey ive only been doing C++ for a little while so dont criticize me or anything. well this is it. what it does is check to see if the number is valid or not. i think it is just bypassing most of the code. no matter what number is entered, it always returns "The number is not valid". please help me. thanx
     
  3. Unread #2 - Feb 9, 2008 at 5:12 AM
  4. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    problem with program!!

    that's terrible. You should use arrays, or something similar.

    Now what is it exactly that you are trying to do? I can understand that you want to check the remainder of a mathematical operation, but not much more than that.

    Your description is extremely unhelpful - check validity due to what? What makes the number valid, etc.?
     
  5. Unread #3 - Feb 9, 2008 at 9:25 AM
  6. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    problem with program!!

    Arrays and loop constructs are your friends :)
     
  7. Unread #4 - Feb 9, 2008 at 9:43 AM
  8. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    problem with program!!

    Holy Christ, that's a lot of integers.

    Code:
    int a[17];
    That's an array, with sixteen slots and one null character to end it. You can store your numbers in there very easily -- just specify which slot you're modifying.

    Code:
    a[4] = 0;
    Also, you use the double = sign, which is for comparisons, you need to use a single = to assign a value.
     
  9. Unread #5 - Feb 9, 2008 at 12:45 PM
  10. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    problem with program!!

    LOLOLOLOLOLOLOL IDIOT! Since when did all arrays end with a null character?
     
  11. Unread #6 - Feb 9, 2008 at 1:20 PM
  12. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    problem with program!!

    Don't they have one unusable slot?
     
  13. Unread #7 - Feb 9, 2008 at 3:36 PM
  14. jman007_93
    Joined:
    Jan 7, 2008
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    jman007_93 Member

    problem with program!!

    thanx. i know about arrays and how to do them, but im a little unsure of how to do it for this. what it does for example is if you input the number 8, it multiplies it by 2, 16, then adds those two digits together giving you 7. it doesnt actually perform this, but it should mean the same thing.

    a little more help on arrays for this would be cool.
     
  15. Unread #8 - Feb 9, 2008 at 4:32 PM
  16. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    problem with program!!

    Code:
    #include <stdio.h>
    
    int i;
    int i2;
    
    int main()
    {
      printf( "Enter your number." );
      scanf( "%d", i );
      i2 = i;
      i = i * 2;
      i2 = i2 * 16;
      i = i + i2;
      printf( "\nYour number: %d", i );
    }
    That's how it would work in C (I think).
     
  17. Unread #9 - Feb 9, 2008 at 6:23 PM
  18. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    problem with program!!

    From my experience, you never write the string itself in printf, it fucks up flushing.
    Code:
    printf("%s%d", "Your number: ", i);
    is better. And to your question, only with C strings. It signifies EOS (End of String).
     
  19. Unread #10 - Feb 9, 2008 at 7:24 PM
  20. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    problem with program!!

    Not at all.

    All array indices start at 0.

    so when you declare
    Code:
    int a[17];
    you may access all elements, they just start at 0.

    e.g.
    Code:
    a[0] = 1;
    a[1] = 2;
    a[2] = 3;
    //etc...
    Where my assignments demonstrate which index is what.
     
  21. Unread #11 - Feb 9, 2008 at 9:35 PM
  22. SidStudios
    Joined:
    Mar 14, 2007
    Posts:
    201
    Referrals:
    0
    Sythe Gold:
    0

    SidStudios Active Member

    problem with program!!

    What exactly are you trying to accomplish by making a = 2, then 3, then 4?
     
  23. Unread #12 - Feb 10, 2008 at 1:37 PM
  24. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    problem with program!!

    He's asking if all arrays have one null spot, but only C strings do to signifie end-of-string.
     
  25. Unread #13 - Feb 10, 2008 at 4:08 PM
  26. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    problem with program!!

    I don't use C++...
     
  27. Unread #14 - Feb 11, 2008 at 8:10 PM
  28. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    problem with program!!

    C Strings ...
     
  29. Unread #15 - Feb 11, 2008 at 8:25 PM
  30. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    problem with program!!

    Which would be why advice in a C/C++ forum about non-C stuff would be useless, keep up.
     
  31. Unread #16 - Feb 11, 2008 at 8:33 PM
  32. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    problem with program!!

    You're an idiot, I was just answering your question, douche.
     
< Need Serious Help | c++ code for sending emails >

Users viewing this thread
1 guest


 
 
Adblock breaks this site