one choice not working and another choice being activated twice per use?

this is the one that is happening twice/three times when you type the choice once
1
2
3
4
5
6
7
8
9
10
11
12
if (choice == 'st' || choice == 'ST')
    {
     SheildTackle = (rand() % 25) + 1;
     hitpoints = (hitpoints - SheildTackle);
     cout << "You hit a " << SheildTackle << endl;
     cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";

     hit = (rand() % 20) + 1;
     life = (life - hit);
     cout << "A Bloodfly his " << hit << endl;
     cout << "You have " << life << "hitpoints left.\n";
    }


for those of you wondering, i managed to fix it, and it really was a nub move xD for some reason using multiple letters for a choice such as QQ qq oo etc will cause it to pick the choice twice? and 3 letters = picks the choice 3 times? so i made my st choice into t and my usep one into p and it just works now

this is the one that just acts as if its not there
1
2
3
4
5
6
7
8
9
10
11
12
if (choice == 'st' || choice == 'ST')
    {
     SheildTackle = (rand() % 25) + 1;
     hitpoints = (hitpoints - SheildTackle);
     cout << "You hit a " << SheildTackle << endl;
     cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";

     hit = (rand() % 20) + 1;
     life = (life - hit);
     cout << "A Bloodfly his " << hit << endl;
     cout << "You have " << life << "hitpoints left.\n";
    }


and here the whole script
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>


using namespace std;

int main()
{
    const int MAX_ITEMS = 5;
    string setup[MAX_ITEMS];

    int items = 0;

    setup[items++] = "Dagger";
    setup[items++] = "Sheild";
    setup[items++] = "Leather Hide Curiass";

    srand(time(0));
    int pot = 5;
    int slash = rand();
    int SheildTackle = rand();
    int lunge = rand();
    int hit = rand();
    char choice;
    int hitpoints = 100;
    int life = 100;

    cout << "\t\@@@  @@@ @@@@@@@  @@@@@@@@ @@@  @@@ @@@@@@@  @@@@@@  @@@@@@@  @@@  @@@ \n";
    cout << "\t\@@!  !@@ @@!  @@@ @@!      @@!@!@@@   @!!   @@!  @@@ @@!  @@@ @@!  !@@ \n";
    cout << "\t\@!@@!@!  @!@!!@!  @!!!:!   @!@@!!@!   @!!   @!@!@!@! @!@!!@!  @!@@!@!  \n";
    cout << "\t\!!: :!!  !!: :!!  !!:      !!:  !!!   !!:   !!:  !!! !!: :!!  !!: :!!  \n";
    cout << "\t\ :   :::  :   : : : :: ::  ::    :     :     :   : :  :   : :  :   ::: \n\n";
    cout << "\t\  @@@@@@  @@@@@@@  @@@@@@@@ @@@  @@@  @@@@@@ \n";
    cout << "\t\ @@!  @@@ @@!  @@@ @@!      @@!@!@@@ @@!  @@@\n";
    cout << "\t\ @!@!@!@! @!@!!@!  @!!!:!   @!@@!!@! @!@!@!@!\n";
    cout << "\t\ !!:  !!! !!: :!!  !!:      !!:  !!! !!:  !!!\n";
    cout << "\t\  :   : :  :   : : : :: ::: ::    :   :   : :\n\n";
    cout << "\n\nIn this mini game you will be pitted against various monsters";
    cout << " from krentark.\n";
    cout << "can you survive?\n";

    cout << "You Currently have:\n";
    for(int i = 0; i < items; ++i)
    cout << setup[i] << endl;

    cout << "\nYour first fight is against A Bloodfly.\n";

    cout << "When you fight you have to select one of three moves.\n";
    cout << "Slash, SheildTackle, Lunge.\n";

    cout << "\nA Bloodfly: Bzzzzzzz\n";

    char again;
    while(again == 'n' || again || 'N')
    {
    cout << "What would you like to do?\n";
    cout << "Slash (s) SheildTackle (st) Lunge (l): ";
    cin >> choice;

    if (choice == 's'|| choice == 'S')
    {
     slash = (rand() % 30) + 1;
     hitpoints = (hitpoints - slash);
     cout << "You hit a " << slash << endl;
     cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";

     hit = (rand() % 25) + 1;
     life = (life - hit);
     cout << "A Bloodfly his " << hit << endl;
     cout << "You have " << life << "hitpoints left.\n";
    }

    if (choice == 'st' || choice == 'ST')
    {
     SheildTackle = (rand() % 25) + 1;
     hitpoints = (hitpoints - SheildTackle);
     cout << "You hit a " << SheildTackle << endl;
     cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";

     hit = (rand() % 20) + 1;
     life = (life - hit);
     cout << "A Bloodfly his " << hit << endl;
     cout << "You have " << life << "hitpoints left.\n";
    }

    if (choice == 'l' || choice == 'L')
    {
     lunge = (rand() % 20) + 1;
     hitpoints = (hitpoints - lunge);
     cout << "You hit a " << lunge << endl;
     cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";

     hit = (rand() % 25) + 1;
     life = (life - hit);
     cout << "A Bloodfly his " << hit << endl;
     cout << "You have " << life << "hitpoints left.\n";
    }

        if (choice == 'upot')
        {
        if ( pot > 0 )
        {pot = (pot - 1);
        life = (life + 20);
        cout << "you not have" << pot << "left\n";
        cout << "Your health is now" << life << "\n" ;}
        else if (pot = 0)
        {cout << "you do not have enough pot\n";}
        }

    // Declaring Winner
    char weapon;
    if (hitpoints <= 0)
    {
     cout << "You defeated A Bloodfly\n";
     cout << "When you take a weapon, sometimes it may replace";
     cout << " a weapon you already have.\n";

     cout << "Would you like a Rapier (r) Iron Shield (i) Potion(p)\n";
     cin >> weapon;
    // Selecting Weapon
     if (weapon == 'r' || weapon == 'R') // Rapier
     {
      cout << "You've choosen the Rapier.";
      cout << "Your inventory is now:\n";
      setup[0] = "Rapier";
      for (int i = 0; i < items; ++i)
      cout << setup[i] << endl;
     }

     if (weapon == 'i' || weapon == 'I') // Iron Shield
     {
      cout << "You've choosen an Iron Shield.";
      cout << "Your inventory is now:\n";
      setup[1] = "Iron Shield";
      for (int i = 0; i < items; ++i)
      cout << setup[i] << endl;
     }

     if ( weapon == 'p' || weapon == 'P')
     {
      cout << "You've choosen a Poiton";
      cout << "Your inventory is now:\n";
      setup[items++] = "Potion";
      for (int i = 0; i < items; ++i)
      cout << setup[i] << endl;
     }

     cout << "Would you like to continue the battle!<Y/N>";
     cin >> choice;
     if (choice == 'y'|| choice == 'Y')
     
     if (life <= 0)
    {
    cout << "A Bloodfly has defeated you.";
    cout << "You have died";
    return 0;
    }
    }
}
    cout << "Thanks for playing.\n";

    return 0;
}
    }
}
     


Please note: i know the potion reward part after killing a bloodfly is useless, i havent set that up yet, also i know theres no N option yet, im adding that, the only fixes i need are for the ones i mentioned,

ps i put this in the beginners section because i only started coding yesterday and knowing me its probablly something very small i dont see
Last edited on
Topic archived. No new replies allowed.