#include <iostream>
int choice;
double combat_options();
int hit_chance;
double monster_health = 50;
double player_damage_crushing = 15;
double combat();
int main()
{
using namespace std;
cout << " hello and welcome to player vs monster ";
cout << " You are a warrior and suddenly a monster jumps out and attacks you! ";
intro();
combat_options();
combat();
cin.get();
return 0;
}
double combat_options()
{
using namespace std;
cout << " what do you do? \n"
<< " 1) crushing blow ";
return choice;
}
double combat()
{
using namespace std;
if (hit_chance % 100 < 75)
{
cout << " you have succesfully hit the monster for crushing blow";
monster_health -= player_damage_crushing;
cout << "Monsters health :" << monster_health;
}
else
{
cout << " you have missed the monster... ";
}
return monster_health;
}
C++ need help! functions
hi guys trying to re-write one of my current games so that the code is easier to read and easier to modify but i am stuck.
please help me :D
can someone show me how to incorporate a do{ } while() loop so that it repeats combat options untill monster or player is dead?
the syntax goes like so:
with cond being the condition, which is of type "int", so it can be read as code]do { <things-to-do> } while (0 != (cond));
(in C and C++, this is the same for all conditions).
Note that the <things-to-do> are executed once before the condition is tested. Note that the other form is
Here, the condition is always tested first, and only after cond!=0 or cond==true, the <things-to-do> are executed.
In other words, in the while(){} form (called a "pre-test loop"*), the body is executed at least 0 times, in the do{}while() form (called a "post-test loop"*), the body is executed at least 1 time.
*: Anecdote: In german, we say "head controlled loop" ("kopfgesteuerte Schleife") and "foot controlled loop" ("fußgesteuerte Schleife")
do { <things-to-do> } while (cond);
with cond being the condition, which is of type "int", so it can be read as code]do { <things-to-do> } while (0 != (cond));
(in C and C++, this is the same for all conditions).
Note that the <things-to-do> are executed once before the condition is tested. Note that the other form is
while (cond) { <things-to-do> }
Here, the condition is always tested first, and only after cond!=0 or cond==true, the <things-to-do> are executed.
In other words, in the while(){} form (called a "pre-test loop"*), the body is executed at least 0 times, in the do{}while() form (called a "post-test loop"*), the body is executed at least 1 time.
*: Anecdote: In german, we say "head controlled loop" ("kopfgesteuerte Schleife") and "foot controlled loop" ("fußgesteuerte Schleife")
Quote:Original post by phresnel
with cond being the condition, which is of type "int"
In C++ it's bool.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement