September 30th, 2005, 09:07 PM
simple C++ program
I have just started C++ and ran into a question that i am trying to figure out
Write a fragment of code to display the middle value in a unordered set of three values. After displaying the result ask if the user wants to repeat the process. EX. 10 30 12, 12 would be shown.
I need to use a while loop, but beyond that i have confused myself so i was hoping i could get some help
September 30th, 2005, 09:42 PM
Sounds to be like you need to work on your algorithm a bit first...its always helpful to a person new to coding to layout exactly how they are going to solve a problem before trying to jump in and code it (so that you are focused on solving the problem first and then how to code it second and not mixing the two).
So for example,
1. Ask for three values
2. Print 2nd value
3. Goto step 1
Then you look at your simple steps and ask yourself, how would I ask for the three values ? How would I print the 2nd one...how would I go back to the first step ? Congrats, you then have your code fragment...
There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.
(Merovingian - Matrix Reloaded)
September 30th, 2005, 09:54 PM
thank you, after following that i was able to break it down into easier steps.
September 30th, 2005, 09:57 PM
Also, if you can get into the habit of using pseudocode it may help you figure things out more easily. Pseudocode is just writing out your algorithm in english but in a way that transfers easily into code.
September 30th, 2005, 10:13 PM
yeah i ended up just writing down what i needed on a scrap peice of paper, which i then turned into code...much easier