Code:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
string Command;
struct User
{
int UHP; // Users Current Hit Points
int max_UHP; // Users Maximum Hit Points
};
struct Challenger
{
int CHP; // Challengers Hit Points
int max_CHP; // Challengers Maximum Hit Points
};
int main()
{
User Player;
Challenger Enemy;
Player.max_UHP = 100;
Player.UHP = 100;
Enemy.max_CHP = 100;
Enemy.CHP = 100;
int UATK = rand()%10; // Users Attack points
int CATK = rand()%10; // Challengers Attack points
cout<<"As your walking down a path a cloaked swordsman ambushes you.\n";
cout<<"He then challenges you to a fight and you humbly accept.\n";
cout<<"You can Attack.\n";
cin>> Command;
cin.ignore();
if ( Command == "AttacK" || Command == "attack" )
{
Enemy.CHP - UATK;
cout<<"You took out "<< UATK <<" points.\n";
}
cin.get();
}
notice
Code:
cin>> Command;
cin.ignore();
Your program is ending right away because cin.get() waits for a return \n (when you hit enter). The problem is its keeping the enter in queue after you enter the word attack. so after you get the input, you put cin.ignore() which will ignore the next return. Try this and it will work for you.