expected ')' before numeric constant error

on line 28 i keep getting 2 errors the "expected ')' before numeric constant" error and the "expected ')' before ';' token" error any ideas on how i can fix this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
using namespace std;

int main()
{
    int WeaponDamage;
    int Strength;
    int Speed;
    int Mana;
    int PlayerDamage;
    int EnemyDefense;
    int PhysicalResistance;
    int MagicResistance;
    int SpeedResistance;

    Mana = 10;
    Strength = 5;
    Speed = 15;
    WeaponDamage = 10;
    EnemyDefense = 10;
    PhysicalResistance = 2;
    MagicResistance = 2;
    SpeedResistance = 2;

    (PlayerDamage = ((((Strength)*((1)-(PhysicalResistance*0.01))*0.2)*((Speed)*((1)-(SpeedResistance*0.01))0.2)*((Mana)*((1)-(MagicResistance*0.01))*0.2))*((1)+(WeaponDamage*0.001))*((1)+(EnemyDefense*0.001))));

    cout << PlayerDamage << endl;
    system("PAUSE");
    return 0;

}
Good luck finding it in that mess.

Don't try to cram so much on one line. New lines don't cost anything. Code readability is surprisingly important. Spread those calculations across several lines so that you can actually read them and understand what they're doing. Then you'll be able to spot the problem.
Last edited on
could i end the line and keep the single equation going though
Yes. But even that I would recommend against.

EDIT:

Here's the fundamental problem:
You're missing a parenthesis somewhere. Now even if you fix the error, this throws the entire equation into question, because you already know you got the parenthesis wrong... so even if you get around the compiler error the equation itself might still be wrong.

So really, my advise is throw that whole line out and rewrite it. But this time, split it up into different chunks that are simpler and easier to understand.

Something like this:

1
2
3
4
double physical_dmg = Strength * (1.0 - (PhysicalResistance * 0.01)) * 0.2;
double speed_dmg = Speed * (1.0 - (SpeedResistance * 0.01)) * 0.2;
//...
PlayerDamage = physical_dmg * speed_dmg * ...


Don't worry about making extra variables. It will not make your program run slower or use more memory. All it does it make the code easier to read and write.
Last edited on
thx for the help i looked ovr it again and found the problem it works great now
Somewhere in the middle of that line is this bit: SpeedResistance*0.01))0.2 where there is no operator (such as + or *) before the 0.2.

And learn the rules of precedence. There are only + - and * there. Just remember that 2*3+4*5 is interpreted as (2*3) + (4*5) without any need for extra typing. And you certainly don't need an open-bracket the start of the line, or around single items such as (1) or (Speed).

That line urgently needs simplification. I'd also press the 'return' key to split it into separate lines - the compiler won't mind, and it will aid legibility.

I've guessed a bit at the intentions and inserted an extra multiplication sign. This is my version of line 28:
1
2
3
4
5
6
7
8
9
10
11
  PlayerDamage = 
  
    Strength * (1 - PhysicalResistance*0.01) * 0.2
  
    * Speed * (1 - SpeedResistance*0.01) * 0.2
 
    * Mana * (1 - MagicResistance*0.01) * 0.2
  
    * (1 + WeaponDamage*0.001)
  
    * (1 + EnemyDefense*0.001);
Last edited on
Topic archived. No new replies allowed.