Hello everyone I am trying to get it so my program is able to take multiple users worth of data, and then print all of that data once the while loop is finished (I have the counter set at 1 so one new set of information can be entered after the last, but if it hits the limit of two people it will stop and print the information). I have been able to get the information to print out correctly using user input data, but I am unable to get more than one person to enter the data, and I was unable to print out more than one set of data even when I was able to take in more than just one user's data. How would I do these two things? Here is my code that i have so far:
public class credLimit {
public static void main(String[]args){
Scanner input = new Scanner(System.in);
int newBalance = 0;
int credCounter = 1;
while(credCounter <= 2){
System.out.print("Enter account number: ");
int accNum = input.nextInt();
System.out.print("Enter your beginning balance: ");
int beginningBalance = input.nextInt();
System.out.print("Enter your total charges this month: ");
int charges = input.nextInt();
System.out.print("Enter your total credit applied this month: ");
int credit = input.nextInt();
System.out.print("Enter your allowed credit limit: ");
int maxcredLimit = input.nextInt();
newBalance = beginningBalance + charges - credit;
credCounter = credCounter + 1;
System.out.printf("%nAccount number: %d%n", accNum);
System.out.printf("Your new balance: %d%n", newBalance);
if(newBalance <= maxcredLimit)
System.out.printf("You have not exceeded your credit limit. %d%n");
else if (newBalance > maxcredLimit)
System.out.printf("Credit limit exceeded. %d%n");
}
}
I was able to take multiple sets of information in before, but now I can only get one of the users data to be taken, calculated (to determine if their credit limit had been exceeded), and printed out. For some reason it keeps stopping at one user's information instead of letting two user's put in their information, why is that?
Aucun commentaire:
Enregistrer un commentaire