C++ Check Digit

Discussion in 'Software' started by Amy, Nov 25, 2005.

  1. Amy

    Amy Private E-2

    Hi I'm trying to write some programming for a check digit in C++ Version 6.0. I have attached the programming i have done (on a word pro file). Can anyone see where i am going wrong or what else i need to enter?

    Thanks for any help

    Amy xxx
     

    Attached Files:

  2. QuickSilver

    QuickSilver Corporal

    A quick look at your code suggests you're having some trouble with your '=' placements...

    Hopefully this will help a little

    Code:
    int x = 3;
    int y;
    
    y = x;
    This is a single = and is used for an assignment. That is when you use one = you are assigning the contents of one variable into another. Strings are different beasts and you do need to use a string copy function, but for integers, doubles, floats, chars a simple = will do.

    Code:
    int x = 3;
    int y = 4;
    
    if(x == y)
    {
      ..
    }
    Here we are using 2 = (==) and this is a comparison. We are asking whether x is equal to y. Under the covers if statements work on 0's and 1's, a 1 for an if statement means that code gets executed, and a 0 means that the else statement gets executed or the elsif gets considered. when you have a statement like 'x == y' this gets considered and either a 1 or a 0 gets returned... a 1 being 'yes they're equal' and a 0 being 'not equal'

    I see a few occasions in your code (where you are doing comparisons instead of assignments. This will have an odd affect on your execution but is syntactically correct.

    So for each instance ask yourself... am I trying to compare values, or pop the value of 1 variable into another??? I hope that helps get you started in the right direction...
     
    Last edited: Nov 25, 2005
  3. QuickSilver

    QuickSilver Corporal

    By the way this is a very easy mistake... Most programmers make it frequently whilst learning... and if not paying attention even experienced coders can just fall into this trap - especially when comparing in an if statement... Hopefully the above explanations wil help you understand a little better and avoid this pitfall in teh future
     
  4. Amy

    Amy Private E-2

    Thanks alot. I'll change this. Thankyou :D

    Amy
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds