Anyone can help me with C++ ?
yes?/
the link has the questions in it i got half done just having trouble with tolerance
see attached code
@e.mccormick
AH, OK. I see now. You are just doing the averaging once. You need to keep doing so in a loop until you hit the tolerance. However, I do see a bit of a flaw in this... if the tolerance is smaller than the difference between the top and the side. So you need some way to avoid getting stuck if poor values are put in.
Just to show the possibility, I did it as a loop for now: http://dpaste.com/hold/1321350/ Output from looping a few times: http://dpaste.com/hold/1321348/ Oh, and I didn't like the output... so I changed it. The loop does not break the vector part, so no big deal for passing thigns through more than once. What would be needed for the test is to see if things are within the tolerance. So you are checking to see if the absolute value of the difference of adjacent values is < tolerance. You need abs val to account for either direction being higher. Any val that is >, throw false. Make it through all values, throw true. Then change the while loop to run while this is false. Only catch is this: You need to make sure it is smart enough to account for test values that are impossible to satisfy. So like my 10-5-2 example. The gap there is 2.5, but the tolearance is 2. So, should it adjust the tolearance for the top and edgest to the average difference? Or, should it just pass the lowest by the tolerance. Or should the user input be changed to not allow adjacent values that are wider apart than 2x the tolerance?
Oh, and dpaste did not have a C++ thing, so I just did it as JavaScript.... so if the coloring is odd, that is why.
@HappyStudent
why did you use loopy < 5, because for now it updates the temperatures only 4 times. I asked my professor and she told that I had to get 24 values from the user so I updated the code and added a do-while loop that I believe should help me with tolerance values but the loop doesn't work for some reason. Here's the dpaste link: http://dpaste.com/hold/1323853/ I also attached the cpp file incase
I just did 5 to see if the vector would survive the multiple iterations properly. I thought it would, but it was an easy way to test. It shows that some sort of controlled loop, such as a while loop, should get the desired results.
First, for the testing of the rest of this, don't ask the user for input for now. Just make a test harness. In this case, that would just set the input values without user input. Then test the same values every time until you are happy. Then change the values a bit and see if things break. You have a bunch of one dimensional arrays as two dimensions.... I don't see the point of that: double tempT[1][8], tempB[1][8], tempL[4][1], tempR[4][1], tolerance; What is this supposed to do? double tol[6][8]={tolerance}; tolerance has not yet been entered, so this is either 0 or garbage from memory. This is a mess: while (diff[1][1] < tol[1][1] && diff[1][2] < tol[1][2] && diff[1][3] < tol[1][3] && diff[1][4] < tol[1][4] && diff[1][5] < tol[1][5] && diff[1][6] < tol[1][6] && diff[2][1] < tol[2][1] && diff[2][2] < tol[2][2] && diff[2][3] < tol[2][3] && diff[2][4] < tol[2][4] && diff[2][5] < tol[2][5] && diff[2][6] < tol[2][6] && diff[3][1] < tol[3][1] && diff[3][2] < tol[3][2] && diff[3][3] < tol[3][3] && diff[3][4] < tol[3][4] && diff[3][5] < tol[3][5] && diff[3][6] < tol[3][6] && diff[4][1] < tol[4][1] && diff[4][2] < tol[4][2] && diff[4][3] < tol[4][3] && diff[4][4] < tol[4][4] && diff[4][5] < tol[4][5] && diff[4][6] < tol[4][6]); It would be better to make a type bool function that returns true or not.
Here is an example of a test harness for yours: http://dpaste.com/hold/1324136/
As far as I can tell, tol[6][8] and diff[6][8] are not needed.
If we take your grid and put it in Row by Column notation, it becomes this: \(\begin{array}{c|c|c|c|c|c|c|c|c|} &C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 \\ \hline R0 & 00 & 01 & 02 &03 & 04 & 05 & 06 & 07 \\ \hline R1 & 10 & 11 & 12 &13 & 14 & 15 & 16 & 17 \\ \hline R2 & 20 & 21 & 22 &23 & 24 & 25 & 26 & 27 \\ \hline R3 & 30 & 31 & 32 &33 & 34 & 35 & 36 & 37 \\ \hline R4 & 40 & 41 & 42 &43 & 44 & 45 & 46 & 47 \\ \hline R5 & 50 & 51 & 52 &53 & 54 & 55 & 56 & 57 \\ \hline \end{array}\) As your book points out, any square's temperature in the center is changes by the squares adjacent to it. This means 00, 17, 50, and 57 do not matter. They are not adjacent to any internal squares. To make the loops work well, you still need them in the vector, but set them to anything, even 0, and it will not matter. Don't even bother asking the user for them because they are never used at all. A problem that can cause an infinite loop: If [01] = 15 and [10]=5 and the tolerance is 3, then [11] can NEVER be within 3 of both [01] and [10]. Therefore, you must account for the impossible case.
How to write a loop to test the tolerance: The loop should be two nested loops: one for rows and one for columns. The row loop should go from 1 to 5 and the column loop from 1 to 7. At each point see if the absolute value of (tempGrid[row][col]-tempGrid[row-1][col-1]) is <= the tolerance. If any one value fails, you can continue the loop to reducde. Two Caveats: One) The test of 57 will give erroneous results, so you may need to break out before testing 57. However, if it does get to testing 57, then everything else has passed! So at 57 you can return the fact that it passed! Two) The above mentioned impossible case.
ok so i cleaned up the code a bit but the tolerance part still doesnt work :(
Did you look at the "Two Caveats" part? Like I said, you need to deal with those cases in the code.
would those 2 caveats come into play later on once the code works, since those 2 cases will only fix the bugs if user enters improper values
Basically spots 11, 16, 40, and 46, because they can be next to two set values, need only fall within tollearance of one of the two, not both.
my update function starts will 11 and goes to 16 then 40 to 46 one row at a time
bcause i goes from 1 to 4 and j goes from 1 to 6
I mean in the test part.
Going to need to get a c++ compiler back on this machine....
could you please get it ?
I am. Just takes time. My home machine has everything set up.... used to here too.
OK, you went away from it being a loop. It still needs to be a loop for the outwer updates.
This is not yet perfected, but it is more like what I meant: http://dpaste.com/hold/1325306/ It does an infinite loop, but fixing that only means fixing the evaluatior properly.
i think mine was a loop it was inside a for loop
You loop was running once for each element, which is a set number of times that may not be enough to get things to where they need to be.
What you want is a while loop, or do while. While it is not within tolerance, average the temperatures.
i like how your loop works but i dont get the use of int die = 200 and i dont get how the first if statement works to detect infinite loop...also regardless of the tolerance value (be it 1 or 99) it gives out the same results
The dies is there because I know it is an infinite loop at this point. Like I said, the actual evaluations have to change a bit for it to work properly and account for places where things are impossible to match up. The existing loop could probably be used for the center part of it, but the corners make it so you have to do other tests.
oh ok thanks for all your time and help :))
Join our real-time social learning platform and learn together with your friends!