• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Number guessing program

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I would really appreciate some help here.

What I am trying to achieve is to create a simple program that guesses a number from 1 - 15 (which I have done and works).

What I then wanted to do is include some code that reads from and writes to an array. This array includes information about the players, for example;

1. How many players are going to play the game and then reference to how old each player is.

This is purely to demonstrate the use of arrays so even though it doesn't really seem "functional", it will help to understand how it can be used.

So far I have been abler to create the array, but can't seem to work out how to put it all together so the Player 1 and matching age can then be displayed back to the user at the end of the input phase.

It should do the following

1. How many users will play
2. Input how old in years each user is
3. Display back to the user each player number / age ("Player 1 is 42 years old", Player 2 is 18 years old" and so on.
4. Then asks for player names
5. Game begins and goes through the while loop and ends

 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would create a playerclass and create an array of players. And what are you trying to do does a player have to keep guessing while the number isn't found or should everyone take turns?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pedro Da Silva: please edit the subject line so that it describes the problem you want solved.  "Need help please" is not a good subject line.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to parse an int from the user input for line 26 to work.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good: lots of comments / documentation.  Bad: this particular comment (and others) are not needed, as the function of the code is obvious.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote: Good: lots of comments / documentation.  Bad: this particular comment (and others) are not needed, as the function of the code is obvious.


I don't think he added the comments, this is a schoolassignment and I think the teacher added it as to do's...
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see that you must include an "if / then / else if" structure and you written one that works.  One way to improve this is this: if the three conditions cover all possible conditions, then the last "else if" can be just an "else."  My preference would be to have the "less than" and "greater than" conditions first and second , and leave the last condition (equals) off.  So...
 
Pedro Da Silva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, i appreciate the comments and suggestions. Will make some changes and run the code again to see how it goes.

I also can't see any option on the forum pages to change / edit my post - if anyone would be kind enough to point me where i can make changes / edit posts, that would be great.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you might have not enough experience(posts, like or cows) to edit your posts
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Meanwhile, you can ask a staff member (like me) to edit your post for you.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic