Help with if else if and else statements

help, i keep getting errors with this piece of code,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if (playerSword = "WoodenSword")
    {
        playerMoney = playerMoney - woodensword;
        cout << "You bought a Wooden Sword!\n" << "You now have the equivlent gold of " << playerMoney << " coins.";
    }
    else if (playerSword = "StoneSword")
    {
        playerMoney = playerMoney - stonesword;
        cout << "You bought a Stone Sword!\n" << "You now have the equivlent gold of " << playerMoney << " coins.";
    }
    else (playerSword = "IronSword")
    {
        playerMoney = playerMoney - ironsword;
        cout << "You bought an Iron Sword!\n" << "You now have the equivlent gold of " << playerMoney << " coins.";
    }

some body help me please?
if this will help ill show you all the code
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#include <iostream>
#include <string>


int main( void )
{
    using std::cout;
    using std::cin;
    using std::string;
    string playerName;
    string playerSword;
    int playerMoney = 30;
    int woodensword = 5;
    int stonesword = 10;
    int ironsword = 15;
    int gold = 10;
    int iron = 5;

    cout << "You are a knight in the 1600s,\n"
           << "You see a nearby weapon shop that sells:\n"
           << "Wooden Swords, Stone Swords and Iron Swords.\n\n"
           << "You walk in the shop, and notice the prices for each type\n"
           << " of sword." << "You have 3 gold, and the prices for the swords are such:\n"
           << "Wooden Sword: 5 coins\n"
           << "Stone Sword: 10 coins\n"
           << "Iron Sword: 15 coins\n";
    cout << "1 gold is 10 coins\n"
           << "What would you like to buy? (StoneSword, WoodenSword or IronSword)\n";
    cin >> playerSword;

    if (playerSword = "WoodenSword")
    {
        playerMoney = playerMoney - woodensword;
        cout << "You bought a Wooden Sword!\n" << "You now have the equivlent gold of " << playerMoney << " coins.";
    }
    else if (playerSword = "StoneSword")
    {
        playerMoney = playerMoney - stonesword;
        cout << "You bought a Stone Sword!\n" << "You now have the equivlent gold of " << playerMoney << " coins.";
    }
    else (playerSword = "IronSword");
    {
        playerMoney = playerMoney - ironsword;
        cout << "You bought an Iron Sword!\n" << "You now have the equivlent gold of " << playerMoney << " coins.";
    }
    cout << "Thank you for buying the sword!\n";
    cout << "Have a nice day.";

    return 0;

}

i didnt mention this but im new to c++
i have a bit of experience in java and python
Use '==' for equality, not '='. Java uses this syntax as well.
Thank you, I'll try that out, I'm busy right now, ill tell you if it worked. I'm sure your right about the == thing
It worked! Thank you so much for this!
Topic archived. No new replies allowed.