game help

writing a game involving two knights jousting...
My main function has to ask 10 questions (5 about each night), then be able to display the functions then the program will have them attack and so forth.
Here's my main()
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
int main()
 85 {
 86   string n;
 87   cout << "What is the first knights name?" << endl;
 88   cin >> nm;
 89   cout << "What is knights stamina?" << endl;
 90   cin >> stam;
 91   cout << "What is knights weapon?" << endl;
 92   cin >> type;
 93   cout << "What is the weapon's hit chance?" << endl;
 94   cin>> hc;
 95   cout << "What is the weapon's stamina required to use?" << endl;
 96   cin >> sr;
 97   cout << "What is the second knights name?" << endl;
 98   cin >> nm;
 99   cout>> "What is" << name << "stamina?" << endl;
100   cin >> stam;
101   cout >> "What is knights weapon?" << endl;
102   cin>> type;
103   cout << "What is weapon's hit chance?" << endl;
104   cin >> hc;
105   cout << "What is weapon's stamina required?" << endl;
106   cin >> sr;
0  Knight k2(
111 
112   while(k1.on_horse()==true && k1.exhausted()==false
113       &&
114         k2.on_horse()==true && k2.exhausted()==false)
115   {
116     k1.attack;
117     if(did_you_hit==false)
118     {
119       k2.attack;
120     }
121     else
122       k2.on_horse==false;
123   }

I'm having a hard time getting it all worked out because I'm confused on how I could make this work.. I obviously have error and need to add some stuff but I just need some help setting it all up
What errors and problems are you having exactly?

what are you trying to do exactly with the whole
 
Knight k2(
line?
<code> knight k1;
87 cout << "What is the first knights name?" << endl;
88 cin >> nm;
89 cout << "What is knights stamina?" << endl;
90 cin >> stam;
91 cout << "What is knights weapon?" << endl;
92 cin >> type;
93 cout << "What is the weapon's hit chance?" << endl;
94 cin>> hc;
95 cout << "What is the weapon's stamina required to use?" << endl;
96 cin >> sr;
97
98 knight k1(nm,stam,type,hc,sr);
99 k1.display(void);
100
101 knight k2;
102 cout << "What is the second knights name?" << endl;
103 cin >> nm;
104 cout>> "What is" << name << "stamina?" << endl;
105 cin >> stam;
106 cout >> "What is knights weapon?" << endl;
107 cin>> type;
108 cout << "What is weapon's hit chance?" << endl;
109 cin >> hc;
110 cout << "What is weapon's stamina required?" << endl;
111 cin >> sr;
</code>
I fixed that part, but basically I am trying to figure out how to ask these questions and make them part of my code... here is what I have:
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
   1 #include<iostream>
  2 #include<string>
  3 #include"Random.h"
  4 using namespace std;
  5 
  6 class Weapon{
  7   public:
  8     int hit_chance;
  9     int stamina_required;
 10     string weapon_type;
 11     void display (void);
 12     Weapon(string type, int sr, int hc);
 13     int get_stamina_required(void);
 14     bool did_you_hit(void);
 15 };
 16 
 17 void Weapon::display(void)
 18 {
 19   cout<< "hit chance is" << hit_chance << endl;
 20   cout<< "stamina required is" << stamina_required << endl;
 21   cout<< "weapon type is" << weapon_type<< endl;
 22 
 23 }
 24 
 25 int Weapon::get_stamina_required(void)
 26 {
 27    return stamina_required;
 28 }
 29 
 30 bool did_you_hit(void)
 31 {
 32   Random r(1,100);
 33   bool hit=r.get();
 34   if (hit_chance<=hit)
 35   {
 36       did_you_hit==false;
 37 
 38   }
 39   else
 40     did_you_hit==true;
 41 }
 42 
 43  class Knight{
 44    public:
 45         int stamina;
 46 
 47         bool attack();
 48         knight(string n, int stam);
 49         Weapon weapon_in_hand;
 50         bool on_horse;
 51         string name;
 52  };
 53 
 54 Knight:: knight(string n, int stam, &const Weapon)
 55 {
 56 }
 57 
 58 bool Knight::on_horse
 59 {
 60   if (stam<=0)
 61   {
 62     return false;
 63  }
 64     cout << n << "is exhausted" << endl;
 65   }
 66 
 67   else
 68   return true;
 69 }
 70 
 71 bool Knight::attack(const Weapon)
 72 {
 73 
 74   if ( on_horse==true)
 75   {  get_stamina_required;
 76      stamina-=sr;
 77      did_you_hit;
 78 
 79   }
 80 
 81 }
well you have asked questions in your first post with
1
2
cout << "Knights name "<< endl;
//etc 


Are you trying to set the variables of the knight class?
Last edited on
Yes to the knight and weapon class
1
2
3
4
5
Knight k1;

cout << "Knights name? " << endl;
cin >> k1.name;
Last edited on
Topic archived. No new replies allowed.