Inner if statment not working

Ok so I have this inner if statment to get user input but it does not seam to work by doing the statement in the if else block. What is wrong with it? I dont know what I did wrong here.Am I missing some thing in the statement? Thanks for any help

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
#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>

using namespace System;
using namespace std;




//good guy ie player
class Player
{
public:
	int hp;
	int sp;
	int mp;
		
};

class Bot
{
public:
	int hp; //hit points for emeny
	int atk; //damage to player health
};

void atkTimer(){
	cout << "Player attacked please wait" << endl;
	//time guage for attack bar player cannot attck for 5 seconds
	Sleep(5000); //this is in milliseconds
}


	
int main()
{
	//attack related items and skills
	//attack bar
	 bool atb = true; //if false then player cannot attack 
	
	//amount of damage is abitray
	 int slash = 10;         //players pushs x does 10 in damage
	 int flameSlash = 20;    //player pushs s does 20 in damage
	 int shiningStrike = 30; //player pushs v does 30 in damage

	//skill wheel does x in damage
	 int powerDive = 15;
	 int powerCharge = 25;
	 int wildStrike = 35;
	 int renegade = 40;
	 int shiningStars = 50;  
	
	//build player
	Player Maverick;
	Maverick.hp = 1220;
	Maverick.mp = 220;
	Maverick.sp = 100;
	//build bot
	Bot ninja;
	ninja.hp = 500;
	ninja.atk = 20;

	//print off player data
	cout << "Maverick" << endl;
	cout << "Health " << Maverick.hp <<endl;
	cout << "Magic " << Maverick.mp <<endl;
	cout << "Skill " << Maverick.sp <<endl;
	cout <<endl;

	//print off ninja
	cout << "Enemy Ninja Health " << ninja.hp <<endl;
	
	//player battle starts
	while(ninja.hp > 0 || Maverick.hp < 0) //fight until ninja or player dies
	{
		cout << "Attack!" << endl;
		char button; //input for button pressed
		cin >> button;
		//input is either x v or s on key board.
		if(button == 'x')
		{
			ninja.hp -= slash;
		}else if(button == 'v')
		{
			ninja.hp -= flameSlash;
		
		}else if(button == 's')
		{
			ninja.hp -= shiningStrike;
		
		}else if(button == 'l') //activate skill wheel
		{
			cout << "Skill Wheel" <<endl;
			cout << "1 for Power Dive" <<endl;
			cout << "2 for Power Charge" <<endl;
			cout << "3 for Wild Strike" <<endl;
			cout << "4 for Renegade" <<endl;
			cout << "5 for Shining Stars" <<endl;
			

			char button1;
			cin >> button1;
			//inner if else 
			if(button1 == 1)
			{
				ninja.hp -= powerDive;
			
			}else if (button1 == 2)
			{
				ninja.hp -= powerCharge;

			}else if(button1 == 3)
			{
				ninja.hp -= wildStrike;
			
			}else if (button1 == 4)
			{
				ninja.hp -= renegade;
			}else if(button1 == 5)
			{
				ninja.hp -= shiningStars;
			}//end of inner if else
			
		}
		
			
		cout << "Enemy Ninja Health " << ninja.hp <<endl;
		atb = false;
		//ninja stricks like the flu
		Maverick.hp -= ninja.atk;

		atkTimer();
		atb = true; //player can attack now

	
	}//end of while




    return 0;
}
You forgot quotes around numbers on lines 106 110 114 118 121. Now the numbers are treated as ascii char codes. For example char(1) is ☺.
Yeah, you might want to make char button1; into int button1; :)
Thanks both ways worked :) I see it was treating the numbers like int and not chars and the cin was looking for char. I thought It was auto but it is not that it is :)
C++ has very little automation for the programmers, we've got to do most ourselves - and that's the beauty of it :)
Topic archived. No new replies allowed.