-
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
-
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...
-
thank you, after following that i was able to break it down into easier steps.
-
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.
-
yeah i ended up just writing down what i needed on a scrap peice of paper, which i then turned into code...much easier