no output

Hi, does anyone know why when I enter the number of humans and skeletons nothing happens
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <windows.h>
#include <stdlib.h>

using namespace std;

void userInput(float HumanNumber, float SkeletonNumber);
void HumansTurn(int turn, float HumanAttack, float AllSkeletonslife, float HumanNumber, float HumanDamage, float SkeletonHealth, float SkeletonNumber);
void SkeletonsTurn(int turn, float SkeletonAttack, float AllHumanslife, float SkeletonNumber, float SkeletonDamage, float HumanNumber, float HumanHealth);

int main(){

    // defining human properties
    float HumanAttack;
    float HumanHealth = 100;
    float HumanDamage = 70;
    float HumanNumber;
    float AllHumanslife;

    // defining skeleton properties
    float SkeletonAttack;
    float SkeletonHealth = 80;
    float SkeletonDamage = 65;
    float SkeletonNumber;
    float AllSkeletonslife;

    // defining whose turn is on
    int turn = 0;

    // the battle cycle
    

        // user inputs the number of humans
        userInput(HumanNumber, SkeletonNumber);

        //all life of humans and skeletons
        AllHumanslife = HumanNumber * HumanHealth;
        AllSkeletonslife = SkeletonNumber * SkeletonHealth;

        // Humans turn
        HumansTurn(turn, HumanAttack, AllSkeletonslife, HumanNumber, HumanDamage, SkeletonHealth, SkeletonNumber);

        // Skeletons turn
        SkeletonsTurn(turn, SkeletonAttack, AllHumanslife, SkeletonNumber, SkeletonDamage, HumanNumber, HumanHealth);

        //Battle results
        if(AllHumanslife <= 0){
            cout<<"Humans Lost";
        }
        if(AllSkeletonslife <= 0){
            cout<<"Skeletons Lost";
        }
   

    return 0;
}



// the user enters the number of skeletons and humans
void userInput(float HumanNumber, float SkeletonNumber){
    cout << "\t ***  Skeletons vs Humans  ***\n\n\n";
    cout<<"Please enter the number of human soldiers:\n";
    cin>>HumanNumber;
    cout<<"Please enter the number of skeletons:\n";
    cin>>SkeletonNumber;
}

// Humans turn
void HumansTurn(int turn, float HumanAttack, float AllSkeletonslife, float HumanNumber, float HumanDamage, float SkeletonHealth, float SkeletonNumber){
    // when the humans hit
    if(turn = 0){
        // Humans's chance to hit
        HumanAttack = (rand()%100 + rand()%100)/1.8;
            if(HumanAttack <= 60){
                AllSkeletonslife -= HumanNumber * HumanDamage;
                if(SkeletonHealth <= 0){              //doesn't do anything for now
                    SkeletonNumber -= 1;              //doesn't do anything for now
                }
            }else{
                // switch to the other turn
                turn = 1;
            }
            //when attack finished switch to the other turn
            turn = 1;
    }
}

// Skeletons turn
void SkeletonsTurn(int turn, float SkeletonAttack, float AllHumanslife, float SkeletonNumber, float SkeletonDamage, float HumanNumber, float HumanHealth){
    // when the skeletons hit
    if(turn = 1){
        // Skeleton's chance to hit
        SkeletonAttack = (rand()%100 + rand()%100)/1.8;
            if(SkeletonAttack <= 40){
                AllHumanslife -= SkeletonNumber * SkeletonDamage;
                if(HumanHealth <= 0){              //doesn't do anything for now
                    HumanNumber -= 1;              //doesn't do anything for now
                }
            }else{
                // switch to the other turn
                turn = 0;
            }
            //when attack finished switch to the other turn
            turn = 0;
    }

}
 
Because you're passing them into your "userInput()" function by copy, not by reference so the variable residing in "main()" never changes.
Topic archived. No new replies allowed.