else works even when if is true

Hello,
I'm newbie programist and I've problem with if.
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
#include<iostream>
using namespace std;
main()
     {
int xgracza=0, ygracza=0, hpw=0;      
string kierunek;
string akcja;
do
{
cout<<"Aby sie poruszyc, wpisz ruch.\n Aby zaatakowac, wpisz atak\n";
cin>>akcja;
if(akcja=="ruch")  /*Here is the problem*/
 {
 cout<<"Wybrales: "<<akcja<<"\nWpisz:\n North=w przod\n West=w prawo\n";
 cout<<" South=W tyl\n East= w lewo";
 cin>>kierunek;
 cout<<kierunek;
 hpw=0;   
 }
if(akcja=="atak")
 {
 cout<<"Wybrales: Atak.\n";
 hpw=0;    
 }
else  /* This works when if(akcja=="ruch") is true)*/ 
 {
 cout<<"Bledna komenda. Powrot do poczatku\n";
 hpw=1;
 }
}
    
while(hpw!=0);
system("Pause");
return 0; }     
      

Nevermind cout's, they are in polish language (yes, I'm from Poland). I will be glad if you will help me.

Newbie,
Dembeor.

@down
Oh, I didn't know that I have to do so, thanks!
Last edited on
1
2
3
4
5
6
7
8
9
if( condition1 ){/*

*/}
else if( condition 2 ){/*

*/}
else{/*

*/}


In your case the else is not coupled with the first if
Topic archived. No new replies allowed.