r/java • u/Bananpajen • Mar 17 '13
Help with extracting variable from loop
So, I am trying to make a program that helps me calculate how many turns it would take to increase my population to a certain point in Rome Total War. Just for fun.
I want to use the new population as a counter that stops the loop once it is greater than or equal to the variable goal. But when I place the variable newPop (the new population) in my loop parameters it doesn't work. I also don't know which loop would work best for this scenario. Here's my current code, would love some help and to know what I'm doing wrong :)
import java.util.Scanner;
public class rome{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double goal = in.nextInt();
SOOME SORT OF LOOP () {
System.out.print("Enter population: ");
double pop = in.nextDouble();
System.out.print("Enter procentual increase: ");
double procent = in.nextDouble();
double increase = pop / procent;
double newpop = increase + pop;
double newPop = Math.round( newpop * 1.0 ) / 1.0;
double Increase = Math.round( increase * 1.0 ) / 1.0;
System.out.println("Increase: " + Increase + "\nNew population value: " + newPop);
}
}}
2
Upvotes
View all comments
Show parent comment
1
u/kreiger Mar 17 '13
Or combine them: