Yeah, you made a mistake.
The attack and defense variables are in fact the actual stat (the working stat) - not the base stat. That's where your error is coming from.
>Attack and Defense are the working Attack and Defense stats of the attacking and defending Pokémon, respectively.
If you look at the Bulbapedia Example of a damage calculation;
>Imagine a level 75 Glaceon that has the following stats:
It uses the move Ice Fang (Ice, physical, base damage 65) against a level 78 Garchomp:
Garchomp is Dragon/Ground, so it has a double weakness to Ice. Thus, Type = 4. Additionally, Glaceon, being an Ice-type, receives STAB, so STAB = 1.5.
We then plug Modifier into the rest of the formula:
So depending on luck, Glaceon will do damage in the range 170-200 HP. Despite Garchomp's double weakness to Ice, Glaceon's Ice Fang will not defeat it in a single hit.
You'll notice how Glaceon's attack is 123 and Garchomp's defense is 163 - these are their ACTUAL STATS. Not their base stats.
Anyway so, first you need to calculate, or get the actual stat of the Pokemon's defense, attack, special attack or special defense. Since the actual stat already includes the EVs, IVs and Nature, those values are already inputed in that step.
You just made a silly mistake in calculating utilising base stats, rather then actual stats.