hello all. :)
my assignment is to write a program that accepts a charge account number and then determines whether the number is valid by comparing it to the numbers (listed in the array.)
most of my program is correct, except for the last part where it displays whether the number is valid or invalid.
i've figured out it's not going into the if statement, but i don't understand why it's doing that or how to change that.
any help would be greatly appreciated!
:D
import java.util.Scanner;
import java.util.ArrayList;
public class chargeaccount
{
public static void main (String args[])
{
Scanner keyboard = new Scanner (System.in);
int choice = 1;
int choice1 = 1;
int index = 0;
int element = -1;
int element1 = -1;
int number = 0;
int number1 = 0;
boolean found = false;
boolean found1 = false;
int[] chargeaccounts = {5658845,4520125,7985122,
8777541,8451277,1302850,
8080152,4562555,5552012,
5050552,7825877,1250255,
1005231,65452531,3852085,
7576651,7881200,4581002};
do
{
System.out.println("Enter your charge account number:");
number = keyboard.nextInt();
while (!found1 && index < chargeaccounts.length)
{
if(number == chargeaccounts[index])
{
found1 = true;
element1 = index;
}
index++;
}
System.out.println(("Valid? ") + (found1));
System.out.println("");
System.out.println("Would you like to input another number?(Y(0)/N(1)");
choice1 = keyboard.nextInt();
number = 0;
found1 = true;
}
while(choice1 == 0);
}
}