Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2008, 03:08 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
[SOLVED] Need help with Slope (Loops)
I have most of it...I just need the code for where it displays how many the user got correct/incorrect.

Actual Question:
Each time the user enters a slope, the
computer lets him/her know if she is correct or incorrect. If the user is
incorrect, then the program displays the correct answer, before asking
another. Also, the program should keep track of the total number of questions
and the number correct and report this information. Name the program Slope3.

Here is what I have so far:

Code:
import java.util.Scanner; import java.util.Random; class Loop3 { public static void main(String args[]) { int slope = 0; int count = 0; int count2= 0 ; int yInt = 0; int response = 0; Scanner scan = new Scanner(System.in); Random generator = new Random(); String intro = "You will be asked to find the slopes of several lines\n" + "When you want to quit, type -500 for the value of the slope\n"; System.out.println(intro); do { count = count + 1; slope = generator.nextInt(20)+1; yInt = generator.nextInt(20)+1; System.out.println("What is the slope of the line y = " + slope + "x + " + yInt + "?"); System.out.println("You have tried " + count + " times."); response = scan.nextInt(); if(response == slope) { count2 = count2 + 1; System.out.println("Yes! you have tried " + count2 + " times"); } else { System.out.println("No, try again "); } } while (response != -500); } }
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-16-2008, 03:22 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Why don't you use additional variables for that. Depend on the result update the value of it.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 03:28 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You are looking something like this?

Code:
import java.util.Scanner; import java.util.Random; class Loop3 { public static void main(String args[]) { int correct = 0; int incorrect = 0; int slope = 0; int count = 0; int count2= 0 ; int yInt = 0; int response = 0; Scanner scan = new Scanner(System.in); Random generator = new Random(); String intro = "You will be asked to find the slopes of several lines\n" + "When you want to quit, type -500 for the value of the slope\n"; System.out.println(intro); do { count = count + 1; slope = generator.nextInt(20)+1; yInt = generator.nextInt(20)+1; System.out.println("What is the slope of the line y = " + slope + "x + " + yInt + "?"); System.out.println("You have tried " + count + " times."); response = scan.nextInt(); if(response == slope) { count2 = count2 + 1; System.out.println("Yes! you have tried " + count2 + " times"); correct++; } else { System.out.println("No, try again "); incorrect++; } System.err.println("You have " + correct + " success and " + incorrect + " failed.\n"); } while (response != -500); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-16-2008, 03:28 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Why don't you use additional variables for that. Depend on the result update the value of it.
I don't really know what that means (sorry), but I am just trying to get some help or code on what to put to keep track of how many the user got correct and incorrect.
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-16-2008, 03:29 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I think your solution is on the 3rd replay.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-16-2008, 03:35 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
OMG...lol...sorry. Solved!
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-16-2008, 03:35 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Did you want to display the correct result if the users' answer is wrong?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-16-2008, 03:38 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by Zebra View Post
OMG...lol...sorry. Solved!
If you solve the question, please mark the thread solved.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-17-2008, 02:51 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
Alright got it to work. Thanks!
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 04-18-2008, 04:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Nice to hear that
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about loops BHCluster New To Java 4 04-16-2008 06:40 PM
[SOLVED] Need help with Loops...please! Zebra New To Java 5 04-10-2008 02:44 PM
Loops (while do etc) manupr New To Java 1 01-15-2008 04:59 AM
Nested loops? gabriel New To Java 4 08-06-2007 05:51 PM
Help me: loops in java silvia New To Java 3 07-19-2007 07:47 PM


All times are GMT +3. The time now is 10:23 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org