unknown1 Posted September 16, 2010 Share Posted September 16, 2010 Hello, just starting to learn c++ but am still a noob... Wrote a small program and doesn't work at all and was hoping someone could tell me why? Thanks in advance! #include <iostream> #include <windows.h> #define VK_OEM_PLUS 0xBB using namespace std; class player { public: int health; void decreaseHealth() { if(GetAsyncKeyState(VK_OEM_PLUS)){health--;} } }; int main() { player a; a.health = 100; while (a.health >0){ cout << "Hit the plus key to attack \n"; a.decreaseHealth(); cout << a.health; char f; cin >> f; return 0; } } Quote Link to comment https://forums.phpfreaks.com/topic/213546-c/ Share on other sites More sharing options...
unknown1 Posted September 16, 2010 Author Share Posted September 16, 2010 Okay, don't need the help anymore but thanks anyways. in case someone else is just learning c++ and wants an example.... here is the code I wrote. #include <iostream> #include <windows.h> #include <stdlib.h> using namespace std; class player { public: int health, skill; void increaseHealth() { health++; } void decreaseHealth() { health--; } void attack() { char key; if(cin.get()){ decreaseHealth(); } } }; int main() { player a; cout << "Hit enter key to attack. \n"; for (a.health=100; a.health >0; ){ a.attack(); cout << "You have attacked player a \n" << "\n Health remaining:" << a.health << endl; cout << "\n"; cout << "Hit ctrl x to exit or enter to attack again. \n"; } char f; cin >> f; return 0; } Quote Link to comment https://forums.phpfreaks.com/topic/213546-c/#findComment-1111844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.