Jump to content

C++


unknown1

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.