battery flag charging

i need help getting BATTERY_FLAG_CHARGING to work in lines 53-60

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Windows.h>
#include <iostream>

using namespace std;

int main()
{
	while (true)
	{
		SYSTEM_POWER_STATUS status;
		GetSystemPowerStatus(&status);

		int Battery = status.BatteryLifePercent;

		cout << "Battery status is:";

		if (Battery <= 20) //if % is less than or equal to 20
		{
			cout << " low, your should consider charging your battery" << endl << "your batter percentage is " << Battery << endl;
			Sleep(10000);//wait 10000 seconds
			continue;//restart program after 1000 seconds
		}
		else if (Battery >= 21 && Battery <= 50) //if % is greater than or equal to 50 and less than or equal to 79
		{
			cout << " ok, should still consider charging your battery" << endl << "your batter percentage is " << Battery << endl;
			Sleep(10000);//wait 10000 seconds
			continue;//restart program after 1000 seconds
		}
		else if (Battery >= 51 && Battery <= 79) //if % is greater than or equal to 50 and less than or equal to 79
		{
			cout << " average, should still consider charging your battery, but not needed" << endl << "your batter percentage is " << Battery << endl;
			Sleep(10000);//wait 10000 seconds
			continue;//restart program after 1000 seconds
		}
		else if (Battery >= 80 && Battery <= 99) //if % is greater than or equal to 80 and less than or equal to 99
		{
			cout << " good, shouldnt need to charge your battery" << endl << "your batter percentage is " << Battery << endl;
			Sleep(10000);//wait 10000 seconds
			continue;//restart program after 1000 seconds
		}
		else if (Battery == 100) //if % is egual to 100
		{
			cout << " great, battery is full" << endl << "your batter percentage is " << Battery << endl;
			Sleep(10000);//wait 10000 seconds
			continue;//restart program after 10000 seconds
		}
		else//if no reading
		{
			cout << " not working, or no battery" << endl;
			Sleep(10000);//wait 10000 seconds
			continue;//restart program after 10000 seconds
		}
		if (BATTERY_FLAG_CHARGING)//if charging
		{
			cout << "battery is charging" << endl;
		}
		else//if not charging
		{
			cout << "not charging, running off battery" << endl;
		}
	}
}
BATTERY_FLAG_CHARGING is a bit mask. It needs to be masked with batteryflag.

 
  if (status.batteryflag & BATTERY_FLAG_CHARGING)
can you write it for me because i cant understand what u want me to do.
Replace line 53 with what I provided.

status.batteryflag is a series of bits. You have to do a bitwise and with the named constant to determine if the bit is set.
http://www.cplusplus.com/doc/tutorial/operators/
Topic archived. No new replies allowed.