Before I begin, I want to thank you all for the help. I would recommend not giving me the code but instead point me to where the mistakes are. Thanks!
I've been trying to figure this issue out for the past few hours and I can't seem to see where I went wrong. I am trying to continue to ask for user input until the user enters -1, which is the sentinel value. After the sentinel value is entered, the program displays the integers entered by the user and their sum. For reasons unknown to me, the printed value is only -1 and the sum is completly off. Here's my code:
import java.util.Scanner;
public class UserSum
{
public static void main(String args[])
{
//prompt user to enter numbers
Scanner userInput = new Scanner(System.in);
System.out.print("Enter positive integers. Enter -1 to stop. ");
int integers = userInput.nextInt();
//sum is initially set to 0
int sum = 0;
//execute commands as long as the input does not equal -1
while(integers != -1)
{
//keep gathering user input
integers = userInput.nextInt();
sum += integers;
}
//print the results to the user
System.out.println("You entered: " + integers + ", ");
System.out.println("Sum is: " + sum);
}
}
while(integers >= 0), do you want it to stop if they put negative numbers other than -1?