|
-
February 29th, 2016, 09:29 PM
#1
Need help with this EOF based and running total loop?
Hi, here are the instructions for the project I have to do:
http://pastebin.com/n7wyyDWA
I'm new to java and I'm trying my best to figure this out on my own, but after about 6 hours of trying, my brain is a bit fried. I'd like to know what I'm doing wrong and what I need to add.
Here is what I have so far:
Code:
import java.util.*;
public class p5
{
static Scanner kb = new Scanner(System.in);
public static void main (String[] args)
{
// number entered and the running total
int inputNum, sum = 0;
// count of valid and invalid numbers seen
int numValid = 0, numInvalid = 0;
double average;
System.out.println("Enter a positive value (Ctrl-D to quit): ");
while ( kb.hasNext() )
{
inputNum = kb.nextInt();
if ( inputNum < 0 )
System.out.println("The number " + inputNum + " is invalid.");
else
System.out.println("Enter a positive value (Ctrl-D to quit): ");
}
// System.out.println("The sum of the valid numbers was " + sum + " and the average was " + average + ".");
}
}
I know I need the valid and invalid numbers to add up and create a sum and average, but I have no idea how to do that.
If anyone could shed some light, I'd really like to learn about what I'm doing wrong/right and not just be given the answer. I don't want to seem like I'm cheating, I just need some guidance.
Thanks!
Tags for this Thread
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
|