I'm having trouble writing a main() function for my program... It needs to include
1. ask 10 questions
2. create two knights
3. Have each knight display.
4. have the two knights joust until one is unhorsed or one is exhausted
A. While loop: ask 4 questions in the condition of the while statement:
1. knight1 is not exhausted and
2. knight2 is not exhausted and
3. knight1 is on horse and
4. knight2 is on horse
B. Inside while loop, have knights attack each other, unhorse when appropriate.
C. Inside while loop, have each knight display.
D. (end of loop. Back up to 4A)
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
|
93 int main()
94 {
95 cout << "What is the first knights name?" << endl;
96 cin >> Knight k1;
97 cout << "What is" << name << "stamina?" << endl;
98 cin >> k1_stamina;
99 cout << "What is knights weapon?" << endl;
100 cin >> k1_weapon;
101 cout << "What is the weapon's hit chance?" << endl;
102 cin>> hc;
103 cout << "What is the weapon's stamina required to use?" << endl;
104 cin >> sr;
105 cout << "What is the second knights name?" << endl;
106 cin >> Knight k2;
107 cout>> "What is" << name << "stamina?" << endl;
108 cin >> k2_stamina;
109 cout >> "What is knights weapon?" << endl;
110 cin>> k2_weapon;
111 cout << "What is weapon's hit chance?" << endl;
112 cin >> hc;
113 cout << "What is weapon's stamina required?" << endl;
114 cin >> sr;
115
116 Knight k1;
117 Weapon k1_weapon;
118 int k1_stamina;
119
120 Knight k2;
121 Weapon k2_weapon;
122 int k2_stamina;
123
124 while(k1=on_horse)
125 {
126 k1.attack;
127 if(did_you_hit=false)
128 {
129 k2.attack;
130 }
131 else
132
133 }
134
135 }
|
I've been trying for a while and just am not sure about my while loop...
here's the rest of the code which I haven't finished yet either... Please help if you can
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
|
#include<iostream>
2 #include<string>
3 #include"Random.h"
4 using namespace std;
5
6 class Weapon{
7 private:
8 int hit_chance;
9 int stamina_required;
10 string weapon_type;
11 public:
12 void display (void);
13 Weapon(string type, int sr, int hc);
14 int get_stamina_required(void);
15 bool did_you_hit(void);
16 };
17 Weapon:: Weapon(string type, int sr, int hc)
18 :hit_chance(hc), stamina_required(sr), weapon_type(type)
19 {
20 }
21
22 void Weapon::display(void)
23 {
24 cout<< "hit chance=" << hit_chance << endl;
25 cout<< "stamina required=" << stamina_required << endl;
26 cout<< "weapon type is" << weapon_type<< endl;
27
28 }
29
30 int Weapon::get_stamina_required(void)
31 {
32 return stamina_required;
33 }
34
35 bool did_you_hit(void)
36 {
37 Random r(1,100)
38 int prob=r.get();
39
40 if (hc<prob)
41 {
42 return false;
43 }
44 else
45 return true;
46 }
48 class Knight{
49 private:
50 int stamina;
51
52 public:
53 bool attack();
54 knight(string n, int stam);
55 Weapon weapon_in_hand;
56 bool on_horse;
57 string name;
58 };
59
60 Knight:: knight(string n, int stam)
61 :name(n), stamina(stam)
62 {
63 }
64
65 bool Knight::on_horse
66 {
67 if (stam<=0)
68 {
69 return false;
70 }
71 if(false)
72 {
73 cout << n << "is exhausted" << endl;
74 }
75
76 }
77 else
78 return true;
79 }
80
81 bool Knight::attack()
82 {
83
84 if ( on_horse=true)
85 { get_stamina_required;
86 stamina-=sr;
87 did_you_hit;
88
89 }
90
91 }
|