battery %

i can tget this to work i dont know how to make it be if between two numbers ex. if answer between 10 and 20 than true

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
#include <Windows.h>
#include <iostream>

using namespace std;

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

		int life = status.BatteryLifePercent;

		cout << "Battery staus is:";

		if (life <= 20) // i want this if % is less than or equal to 20
		{
			cout << " low, your should consider charging your battery" << endl;
			Sleep(10000);
			continue;
		}
		else if (life >= 50 <= 79) // i want this if % is greater than or equal to 50 and less than or equal to 79
		{
			cout << " ok, should still consider charging your battery" << endl;
			Sleep(10000);
			continue;
		}
		else if (life >= 80 <= 99) // i want this if % is greater than or equal to 80 and less than or equal to 99
		{
			cout << " average, shouldnt need to charge your battery" << endl;
			Sleep(10000);
			continue;
		}
		else if (life == 100); // i want this if % is egual to 100
		{
			cout << " great, battery is full" << endl;
			Sleep(10000);
			continue;
		}
	}
}
Last edited on
You have to split it up into two separate comparisons:
1
2
3
4
5
6
7
8
if (life <= 20)
    // ...
else if (life >= 50 && life <= 79)
    // ...
else if (life >= 80 && life <= 99)
    // ...
else if (life == 100) // No semicolon here
    // ... 
Topic archived. No new replies allowed.