Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help in C++ needed

Help in C++ needed

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++javatutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    d project
    wrote on last edited by
    #1

    Hello, I have a problem in writing a program with C++. I have been studying C# and Java but C++ is a way different to me, so I need your help. My task is to make program which: reads an input from a text box than returns the nubers from that input which has two digits and their sum is 9. For example: Input: 12 231 81 53 522 11 63 Output: 81 63 I need it a ssimple as possible so I could understand it. Thank you in advance.

    J D 2 Replies Last reply
    0
    • D d project

      Hello, I have a problem in writing a program with C++. I have been studying C# and Java but C++ is a way different to me, so I need your help. My task is to make program which: reads an input from a text box than returns the nubers from that input which has two digits and their sum is 9. For example: Input: 12 231 81 53 522 11 63 Output: 81 63 I need it a ssimple as possible so I could understand it. Thank you in advance.

      J Offline
      J Offline
      Jan Sommer
      wrote on last edited by
      #2

      Well I'm no math mastermind, but I think a way to solve your problem would be something like this... if(input > 9 && input < 100) { //if the input is above 9 and under 100 then we pretty sure only have 2 digits int n; n = input / 9; if(n*9 == input) { //The sum is 9 } } this only checks ONE input - you got to figure out a way to split the input by spaces and loop through it. Again, I have no clue if this is the simplest solution, but it should work

      J 1 Reply Last reply
      0
      • J Jan Sommer

        Well I'm no math mastermind, but I think a way to solve your problem would be something like this... if(input > 9 && input < 100) { //if the input is above 9 and under 100 then we pretty sure only have 2 digits int n; n = input / 9; if(n*9 == input) { //The sum is 9 } } this only checks ONE input - you got to figure out a way to split the input by spaces and loop through it. Again, I have no clue if this is the simplest solution, but it should work

        J Offline
        J Offline
        Jan Sommer
        wrote on last edited by
        #3

        we also might have a little problem with "int n;" because if "input / 9" gives decimals like 6.6, it will be converted to 7. so you might want to use a double there instead of int.

        1 Reply Last reply
        0
        • D d project

          Hello, I have a problem in writing a program with C++. I have been studying C# and Java but C++ is a way different to me, so I need your help. My task is to make program which: reads an input from a text box than returns the nubers from that input which has two digits and their sum is 9. For example: Input: 12 231 81 53 522 11 63 Output: 81 63 I need it a ssimple as possible so I could understand it. Thank you in advance.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          The first order of business would be to break the problem down into more manageable pieces. Rather than try to solve the overall problem at once, instead try and solve the individual pieces and the larger problem will solve itself. Roughly:* Get input from an edit control

          • Tokenize that input

          • For each token, determine if it is 2 digits and if the sum of the digits is 9

          • If so, print that token

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups