C++, 2 dimensional arrays ! So I have to solve this problem: http://screencast.com/t/pj9XALij That's my code for the problem: http://pastebin.com/f6nVAhPD I am stuck at part (f) , my results are not giving me the correct answer. Can you please help me find out what I am doing wrong ?
The problem is in how you are finding your fours. For doing this mathematically, you can look into using %. Or, you could use to_string() and then search the string.
One thing you can do is temporarily turn off the table cout, then turn on something that prints out what you find for fours. You should get smething like: 4 4 14 24 4 24 40 40 45 24 42 48 54 14 42 49 24 40 48 64 45 54 40 Sum of all numbers: 3025 There are 51 numbers that are evenly divisible by 3. There are 23 numbers that have a 4 in them.
Changed just enough to print what fours you are owingspaning, it is: http://pastebin.com/YGvZdSAi Which gets me: 4var 4var 4n 4var 4var 4var 4var 4var 4var 4var 4var 4var 4var 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 Sum : 3025 Divisible : 51 Fours : 13
owingspaning ... ummm.... I am gonna blame that one on the cold medicine! Makes things more interesting that usual. I think I meant evaluating. Also, I now have code that does this: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 Sum of all numbers: 3025 There are 51 numbers that are evenly divisible by 3. There are 23 numbers that have a 4 in them. Sum of row six is: 330 Column sums in the format of <colum#>:<sum> 1:55 2:110 3:165 4:220 5:275 6:330 7:385 8:440 9:495 10:550 Find is a number is in a row. What ROW to search? 7 What NUMBER to look for? 35 35 is in row 7. The sum of the upper right to lower left diagonal is: 220 The sum of the upper left to lower right diagonal is: 385 And: What ROW to search? 7 What NUMBER to look for? 11 11 is not in row 7. For ones that are not there.
Thanks a lot
Did you work out with % what math you need to do to find things with a 4 in them? One other thing, you need to test 40 to 49 differently than the rest of the numbers in this range if you do it by math.
If you think about it, you find the things dividable by three using var%3=0, right? But what if var%3=1, what would you be finding? Well, all things that when divided by 3 had a remainder of 1. Now, how can use use that basic concept to find things that have a 4 in them? It won't be %3 or %4, but it will be %something.
Join our real-time social learning platform and learn together with your friends!