testing multiple int alongside one another to see if they match a number

This is a discussion on testing multiple int alongside one another to see if they match a number within the C Programming forums, part of the General Programming Boards category; I'd like to compare a few variables to see whether they match a certain number if strung together for example ...

  1. #1
    Registered User redruby147's Avatar
    Join Date
    Sep 2008
    Location
    England
    Posts
    37

    Question testing multiple int alongside one another to see if they match a number

    I'd like to compare a few variables to see whether they match a certain number if strung together for example

    Code:
    if (("%d%d%d", first, second, beg) == "2000");
    Any help is greatly appriciated.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,976
    One approach is to convert them to strings, concatenate the strings, then compare the final result to the other number as a string.

    Another approach is to use mathematics: add the numbers up and compare. The limitation of course, is in the range of whatever type is used (and you have to either assume that the numbers are in the range [0,9] or it gets tricky).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 07:35 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

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