Thread: Code is wrong but no idea why(rand+srand+conditional)

  1. #1
    Registered User
    Join Date
    Mar 2023
    Posts
    2

    Code is wrong but no idea why(rand+srand+conditional)

    Here in this code, I want to generate a random number to be guessed by a user. When the input number entered by user is greater than the random number, it must show "Enter lower number", but for the opposite, "Enter higher number", however, if equal, the loop will stop.
    But, somehow I did not get to the destination that I wanted and I don't know why. Please help me explain. Thank you.Code is wrong but no idea why(rand+srand+conditional)-screenshot-2023-03-05-172228-jpgCode is wrong but no idea why(rand+srand+conditional)-screenshot-2023-03-05-172452-jpg

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The scanf is wrong. The &guess should not be in quotes.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Mar 2023
    Posts
    2
    Thank you so much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does rand() and srand() together?
    By bos1234 in forum C Programming
    Replies: 2
    Last Post: 08-28-2013, 10:12 PM
  2. srand and rand
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 10-12-2008, 07:09 AM
  3. Rand and srand
    By JFonseka in forum C Programming
    Replies: 5
    Last Post: 02-26-2008, 10:36 PM
  4. srand() and rand()
    By Mr.Sellars in forum C++ Programming
    Replies: 3
    Last Post: 08-12-2007, 03:19 PM
  5. srand() or rand()???
    By bajanstar in forum C Programming
    Replies: 4
    Last Post: 03-04-2005, 12:58 PM

Tags for this Thread