My first game (HELP)

Hello, I need help with this code. I am trying to build a minus game, where you in the start choose a number and then the program takes that number and then you chose either 1 or 2 and then it minuses with 1 or 2 but can't get it to work right now.

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
#include <iostream>
using namespace std;

int main() {
    double a;
    double Player;
    cout << "Hello, Choose a number." << endl;
    cin >> a;
    cout << "You chose " << a << endl;
    
    while (a > 0) {
    cout << "Press 1 or 2" << endl;
    cin >> Player;
        if (Player == 1) {
        
        cout << "You: -1" << endl << a - 1 << endl << endl;
        cout << "PC: -2" << endl << a - 2 << endl << endl;
        cin >> Player;
        
        } else if (Player == 2) {
        
        cout << "You: -2" << endl << a - 2 << endl << endl;
        cout << "PC: -1" << endl << a - 1 << endl << endl;
        cin >> Player;
        
        } else {
        
        cout << "Invalid answer!" << endl;
        
        }
    }
    system("PAUSE");
    return 0;
}
Last edited on
@RebootOfficial

In lines 16, 17, 22 and 23, all you are doing is SHOWING the number with a value of less by 1 or 2. You never subtract from the number.
@whitenite1 I tried doing this instead and it still doesn't work whenever I compile it, it looks like this

/compiled/
Hello, Choose a number.
12
You chose 12
Press 1 or 2
2
You: -2
10

PC: -1
11

Press 1 or 2
1
You: -1
11

PC: -2
10

Press 1 or 2
/compiled/
/code/
double a;
double Player;
double b;
double c;
c=1;
b=2;
cout << "Hello, Choose a number." << endl;
cin >> a;
cout << "You chose " << a << endl;

while (a > 0) {
cout << "Press 1 or 2" << endl;
cin >> Player;
if (Player == 1) {

cout << "You: -1" << endl << a-c << endl << endl;
cout << "PC: -2" << endl << a-b << endl << endl;

} else if (Player == 2) {

cout << "You: -2" << endl << a-b << endl << endl;
cout << "PC: -1" << endl << a-c << endl << endl;
/code/
if (Player == 1)
Comparing floating point values with == doesn't work properly. Better use an int
Topic archived. No new replies allowed.