C++ Help in (IF) Condition

Discussion in 'Programming' started by neverbreaktherules, Jan 6, 2009.

  1. #1
    Hey

    i have a program based on school

    i want to do some coding like that

    even if user inserts +1, it shud work as 11 and +2 shud work as 12

    can anybody help me
     
    neverbreaktherules, Jan 6, 2009 IP
  2. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    I honestly have no idea what you just asked, but from what I do understand you don't want an if statement. Do you want a concatenation? (i.e. User adds, 1 + 2 + 3 and they get "123") or do you want addition? (i.e. User adds 1 + 2 + 2 and they get "5"). I'll outline both below:

    For concatenation you're going to need to make a string, and then do something like:

    your_string = your_string + user_input_number;
    Code (markup):
    Where your_string is the string holding your number string ("123") and user_input_number is the number that was just passed in by the user.

    Alternatively, if you want to add you can just do:
    your_string += user_input_number
    Code (markup):
    Again, if you could be more detailed in what you need I can provide better assistance :)
     
    Louis11, Jan 7, 2009 IP
  3. neverbreaktherules

    neverbreaktherules Banned

    Messages:
    596
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i mean to say
    when anybody enters "+1" it shud be automaticaly replace by 11 and +2 replace by 12
     
    neverbreaktherules, Jan 7, 2009 IP
  4. dprundle

    dprundle Peon

    Messages:
    399
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if (i == "+1") { i = 11; }
     
    dprundle, Jan 7, 2009 IP
  5. dmcybox

    dmcybox Banned

    Messages:
    225
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ohh, I can do that..I'm a c++ programmer..send to me your variables for the input and the output part..
     
    dmcybox, Jan 7, 2009 IP
  6. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Well then you need what dprundle said:

    
    
    if(input == '+1')
      input = '11';
    
    else if(input == '+2')
      input = '12';
    
    
    Code (markup):
     
    Louis11, Jan 7, 2009 IP
  7. dmcybox

    dmcybox Banned

    Messages:
    225
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Maybe you can use a loof method on that..It is more easier..

     
    dmcybox, Jan 7, 2009 IP