-
March 31st, 2013, 12:25 PM
#1
Not sure what kind of code to write
The program is called Hi-Low, where the computer generates a random number and the user inputs guesses.
The problem im facing is trying to find out which loop or function to use to display the output properly.
Everytime the user enters a guess, it displays if their guess is low or high and then tells them to try again until they get it correct.
It also displays the number of tries at the bottom of the screen.
What can I use to allow the attempts to scroll through, but then the bottom refreshes the number of tries.
For example, after two attempts the screen would look like:
--------------------------------------------------------------------
Enter your guess <1 - 100>: 50
LOW
Enter your guess <1 - 100>: 75
CORRECT
Games played: 2
--------------------------------------------------------------------
-
March 31st, 2013, 01:00 PM
#2
Re: Not sure what kind of code to write
You need to design the program first before you start coding! Break the requirements down into its parts. Think about what's needed in terms of user input, loops, output etc. From your previous assignments you should have all the knowledge needed to easily produce this program design and code. If you and I were sitting opposite each other to play this game, and I had to guess the number of which you thought, how would you do it?
You can't keep asking us how to do your assignments. You have to apply knowledge learnt from previous assignments to new ones. This is how you learn how to program. If we keep providing you with the details of how you do things, you're not really learning - you're just trying things that we've said until it works without really understanding why.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 31st, 2013, 01:08 PM
#3
Re: Not sure what kind of code to write
So on this program, I have started off first by creating parts of the program individually.
I created a intro page that just couts the rules, etc.
created a random number generator and a loop for the user to guess numbers until they get it right..
currently working on how to keep track of the number of tries, the number of games (number of times the program has been ran)
and the average tries per game.
I'll have to create loops for the game to start/stop
A round loop for each round (don't understand what this means..waiting prof feedback)
a loop for guesses (think I have this one done)
so this time, im trying to design the program before I write it, so maybe ill create less errors.
Im thinking a do while loop, but can I nest inside those? Surely so.
-
March 31st, 2013, 01:10 PM
#4
Re: Not sure what kind of code to write
well youre right, I have been. But like you said and someone said in my last thread.... Im going to try to write out the program steps on notebook and then write the code from that.
-
March 31st, 2013, 01:18 PM
#5
Re: Not sure what kind of code to write
So here's how Im thinking about the design.
1. <Into>
2. clear screen
3. com generates num
do (count number of tries, games & start/stop)
while (guess != num)
if (guess=low) {LOW, try again?}
if (guess=high) {HIGH, try again?}
else(guess=correct){CORRECT, start over?}
Is that a decent design?
-
April 1st, 2013, 03:50 PM
#6
Re: Not sure what kind of code to write
well i received verification from the prof last night that i only display the stats after the user enters the correct answer. So, i did the code how I 'designed' and it worked...so woot.
-
April 1st, 2013, 05:16 PM
#7
Re: Not sure what kind of code to write
Congrats, feels good does it.
-
April 1st, 2013, 05:53 PM
#8
Re: Not sure what kind of code to write
yup, especially when i suck at it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|