Help in C++ needed
-
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.
-
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.
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
-
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
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.
-
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.
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
-