Jump to content

Recommended Posts

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;
}
}

Link to comment
https://forums.phpfreaks.com/topic/213546-c/
Share on other sites

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;

}

Link to comment
https://forums.phpfreaks.com/topic/213546-c/#findComment-1111844
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.