I recently got assigned a homework to make code in a different language, the only language I have worked with in python. What my code should do is ask the user for an input, and then first set it as the high, low and start calculating an average. However, I'm having 2 problems right now. One, my line 24 says string can't convert to an integer. However, I though I already told the program to allow it. If someone could help me that would be greatly appreciated.
package hgp.pkg13.pkg16;
import java.util.Scanner;
public class HGP1316 {
//Declaration of variables
static int Running_total = 0;
static double Average = 0.0;
static int User_input = 0;
static double counter = 0.0 ;
static int Highest_input = -1;
static int Lowest_input = -1;
public static void main(String[] args) {
//Intro Program (Optional)
{
System.out.println("This program will give you the highest, lowest, and average of the integers you \n"
+ "enter. To end enter a negative number ");
}
//2. Ask user to enter a positive integer (or a negative integer to stop)
//3. Record the user's input
//4. Test the input >= 0
while (User_input >=0){
Scanner user_input = new Scanner( System.in );
Integer User_input;
System.out.print("Please enter an integer: ");
User_input = user_input.nextInt();
//4a. If it is true that input >= 0
if (User_input >= 0)
{
//4a1Add the input to "running total"
Running_total = Running_total + User_input;
//4a2. Increment "number of inputs counter"
counter = counter + 1;
//4a3. Test if "number of inputs counter" is equal to 1
if (counter == 1)
{
//4a31. If true, replace both "highest input" and "lowest input" with the input
Highest_input = User_input;
Lowest_input = User_input; }
//4a5. If the input > "highest input" then replace "highest input" with input
if (User_input > Highest_input)
{
Highest_input = User_input;
}
//4a6. If the input < "lowest input" then replace "lowest input" with input
if (User_input < Lowest_input)
{
Lowest_input = User_input;
}
//4b. If false
//4b1. Goto step 5
else;
{
//5. Calculate average (formula: "running total" /"number of inputs counter" )
Average = (Running_total / counter);
//6. Display/communicate "highest input", "lowest input" and average
System.out.println ("The Highest value entered was : "+ Highest_input);
System.out.println ("The Lowest value entered was : " + Lowest_input);
System.out.println("The Average of enteries was : "+ Average);
//7. Terminate
}
}
}
}
}
The problem that I have now encountered is it goes through the whole loop instead of reasking for the users input. It is probably to do with my {} but I'm not sure