Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C++ help


  • Please log in to reply
10 replies to this topic

#1 a1sporty15

a1sporty15

  • Members
  • 18 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Connecticut
  • Local time:03:15 PM

Posted 02 December 2008 - 06:05 PM

I have to write a program that makes the computer guess your number. Ok first you input your number then the computer guesses it such as "is your number greater than 25 then less than 37 until it reachers your number. I have this all done but it does not seem to work.. It compiles normally and everything but the out put does not work....

http://www.copypastecode.com/codes/view/1327

BC AdBot (Login to Remove)

 


#2 a1sporty15

a1sporty15
  • Topic Starter

  • Members
  • 18 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Connecticut
  • Local time:03:15 PM

Posted 02 December 2008 - 06:11 PM

Also there has to be an easier way to write this program...

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:15 PM

Posted 02 December 2008 - 06:31 PM

I have this all done but it does not seem to work.

'

What specifically does that mean? There are an infinite number of ways to screw up cod, and I don't have time to wonder. Does it go into an infinite loop? Does it do nothing? Does it print out 'kiss off'? What are you expecting to happen, and at what point is it not doing what you expect it should? Have you tried dumping the contents of whatever variables you may be using to the console to see is they contain what you think they contain? Are you dumping your variables to the console right before any 'if' statements to see that you have the values that you think you have?

cout is your friend.

EDIT: There is a much better way to do that. If your number is between one and 50, then the very first guess should be half of that....25. So if I were you, I would have a variable holding the max, which is 50. I would have a variable called min, which at the beginnig would be zero. If the number was greater than 25, then the new min would be 25, and the max would remain at 50. If the number was below 25, then the new max would be 25. Then I would have the application guess the number that was halfway between the max and the min, and so on, until the numbe was guessed. That way, you can use a function, pass it the min and max, and return whatever number is halfway between.

#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:15 PM

Posted 02 December 2008 - 06:47 PM

Here's what I wrote to do this:

Removed by admin...
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:15 PM

Posted 02 December 2008 - 06:51 PM

Post removed. Come on Billy. You know better than that. We never give code......... :thumbsup:

#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:15 PM

Posted 02 December 2008 - 06:53 PM

Post removed. Come on Billy. You know better than that. We never give code......... :thumbsup:

We don't? Oh... sorry Groovicus.. won't do that again.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#7 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:15 PM

Posted 02 December 2008 - 06:57 PM

We teach how to code, and how to solve problems. We can best help by making suggestions, and letting people discover for themselves how to solve the problem. That's how we make programmers. :thumbsup:

#8 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:15 PM

Posted 02 December 2008 - 07:00 PM

Alright... @a1sporty15

Your code is cut off in that link. Might I suggest pastebin instead?

http://pastebin.com

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#9 a1sporty15

a1sporty15
  • Topic Starter

  • Members
  • 18 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Connecticut
  • Local time:03:15 PM

Posted 07 December 2008 - 12:32 PM

http://pastebin.com/m514b4976

thank you for your help :thumbsup:

#10 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:15 PM

Posted 07 December 2008 - 12:45 PM

Alright.. I think you need to approach this problem a little differently. A ton of nested IF conditionals is not going to help you in the event a simple thing changes: Bounds for the guessed number.

See if you can find a way to make it general; that is, I can change the high and low numbers without program modification.

Try playing around with some of the other Control Structures, such as For, Do...While, and/or While loops.

Try to write your program using a pair of defines for the high and low bounds... i.e.

//Run for number between 0 and 100
#define highnumber 100
#define lownumber 0

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#11 a1sporty15

a1sporty15
  • Topic Starter

  • Members
  • 18 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Connecticut
  • Local time:03:15 PM

Posted 07 December 2008 - 12:46 PM

hmm i'll read up on it thank you :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users