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
#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>
usingnamespace System;
usingnamespace 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;
}elseif(button == 'v')
{
ninja.hp -= flameSlash;
}elseif(button == 's')
{
ninja.hp -= shiningStrike;
}elseif(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;
}elseif (button1 == 2)
{
ninja.hp -= powerCharge;
}elseif(button1 == 3)
{
ninja.hp -= wildStrike;
}elseif (button1 == 4)
{
ninja.hp -= renegade;
}elseif(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;
}
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 :)