# Thread: Luhn's Algorithm "Unexpected Type" Compiling issue.

1. Member Join Date
Sep 2015
Posts
13
Rep Power
0

## Luhn's Algorithm "Unexpected Type" Compiling issue.

Java Code:
```//Scanner used for variable value input.
import java.util.Scanner;

public class LuhnValidator{
public static void main(String[] args){

//Variables (Used for input, processing, and outputted values).

//Array ""int[] ccNmbr = new int", used for inputting 16 values into variable "int x;".
int[] ccNmbr = new int;

//"int inputCarry;" used for inputted values of array "ccNmbr" moved into processing.
int inputCarry;

//"int i;" used for "for" statement processing;
int i;

//"double" is a variable used to contain the values of double numbers.
int doubled;

//"int num1;" is equal to first digit of double digited value(s).
int num1;

//"int num2;" is equal to "num1 / 10" so that second digit of double digited value(s) is given.
int num2;

//"int addFin;" is equal to the addition of variables "num1" and "num2" together.

//"int other;" used other values not used for addition of all value put into output variable "int validation;".
int other;

//Output carrier variable "int validation;" is for finished product [values].
int validation;

//Output variable 1 "int validity".
int validity;

//"int finNum1;" has the same process of variable "int num2;".
int finNum1;

//Instantiating Scanner "luhn" for input.
Scanner luhn = new Scanner(System.in);

//For statement for looping of and inputting of values of array "ccNmbr".
for(i=0; i<=16; i++){
System.out.println("Please input sixteen digit credit card number: ");
ccNmbr[i]=luhn.nextInt();
ccNmbr[i]=inputCarry;
}

//Proccessing of values and data inputted for final output with variable "validation", (Luhn's algorithm is a four step process), 1). Choose every other number in credit card id [even values in this case], then double them. 2). If the number is a double digit, separate into into single digit values [num1 = x % 10; num2 = x/10]. 3). All other numbers are added together to get final output. 4). If the value does not end in 0, then it is not a valid credit card number.

if((inputCarry%1=3)){
doubled=(inputCarry*inputCarry);
}

if(doubled >= 10){
num1 = (doubled % 10 + 1);
num2 = (num1 / 10);
}

if((inputCarry%2=0)){
other = (inputCarry%2=0);
validation = (doubled + addFin + other);
}

//Output of values using variables using variable "validity". Using Luhn's Algorithm, if the number ends in zero, then it's a valid credit card number, but if the number does not end in zero, then it's not a valid credit card number.

finNum1 = (validation % 10 + 1);
validity = (finNum1 / 10);
if(validity == 0 || validity == 10 || validity == 20 || validity == 30 || validity == 40 || validity == 50 || validity == 60 || validity == 70 || validity == 80 || validity == 90 || validity == 100){
}
else if(validity >= 1 && validity <= 9 || validity >=11 && validity <= 17 || validity >= 21 && validity <= 29 || validity >= 31 && validity <= 39 || validity >= 41 && validity <= 49 || validity >= 51 || validity <= 59 || validity >= 61 && validity <= 69 || validity >= 71 && validity <= 79 || validity >= 81 && validity <= 89 || validity >= 91 && validity <= 99){
System.out.println("Your credit card is not valid.");
}

}
}```

Hello friends, I've been programming that calculated the validity of credit card by using Luhn's Algorithm, and everytime I have tried compiling, terminal comes back with

LuhnValidator.java:61: unexpected type
required: variable
found : value
if((inputCarry%1=3)){

LuhnValidator.java:71: unexpected type
required: variable
found: value
if((inputCarry%2=0));

LuhnValidator.java:72: unexpected type
required: variable
found : value
other = (inputCarry%2=0);

I've compiled before with the remainder "%" in if statements, what have I done wrong, or what is wrong with Terminal. I recently was infected with trojan OSX/Geneio-A, does this have anything to do with this even though it's an adware trojan. I really don't know, anything can help.
Last edited by William Hagen; 10-21-2015 at 02:52 AM.  Reply With Quote

2. ## Re: Luhn's Algorithm "Unexpected Type" Compiling issue.

what have I done wrong
= is the assignment operator
== is the comparison operator  Reply With Quote

#java 