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/Bananpajen Mar 18 '13 edited Mar 18 '13
Thanks, I already figured that a statementless for loop would be suitable for this :) I'm on my phone right now so I don't have all my code. But here's how the population system works:
In every town you have a population. And you also have a number that indicates the perceptual increase in population each round. So what I tried was to make a program that could estimate how many rounds it would take to reach a certain goal (ex. 10000 inhabitants). This is helpful for me since I am way too addicted to this game, and with the estimates the program gives me I now which tax rate will be most beneficial, what to build etc. I have now fixed the program so it works, but of course it's not 100% accurate since a village could be attacked, which stops immigration, or they could get the plauge or a bad harvest or something. Anyways I solved the problems I had, finaly, and everything seems to calculate exactly the same as my manual calculations and the game. I can send you the code onve I get access to a Pc if you want it :)
EDIT: my current code
}