Adblock breaks this site

problem with program!!

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

  1. jman007_93

    jman007_93 Member

    Joined:
    Jan 7, 2008
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0
    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
     
  2. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    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.?
     
  3. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    Arrays and loop constructs are your friends :)
     
  4. Faskist

    Faskist Tuxhead
    Banned

    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0
    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.
     
  5. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    LOLOLOLOLOLOLOL IDIOT! Since when did all arrays end with a null character?
     
  6. Faskist

    Faskist Tuxhead
    Banned

    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    Don't they have one unusable slot?
     
  7. jman007_93

    jman007_93 Member

    Joined:
    Jan 7, 2008
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0
    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.
     
  8. Faskist

    Faskist Tuxhead
    Banned

    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0
    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).
     
  9. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    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).
     
  10. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    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.
     
  11. SidStudios

    SidStudios Active Member

    Joined:
    Mar 14, 2007
    Posts:
    201
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    What exactly are you trying to accomplish by making a = 2, then 3, then 4?
     
  12. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    He's asking if all arrays have one null spot, but only C strings do to signifie end-of-string.
     
  13. Faskist

    Faskist Tuxhead
    Banned

    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    I don't use C++...
     
  14. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    C Strings ...
     
  15. Faskist

    Faskist Tuxhead
    Banned

    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

    Which would be why advice in a C/C++ forum about non-C stuff would be useless, keep up.
     
  16. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    problem with program!!

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


 
 
Adblock breaks this site