write your question here.
I'm not sure what is wrong with my while loop.
the battle simulator isn't working as i thought it should.
Sometimes it will simple run through the different c-out puts as if there is no random generator when there is indeed one.
sometimes it will go on forever.
As well as sometimes it will say a complete wrong answer at the end: it'll say that there were 1494123145 when there was only 2 to begin with.
It also looks like it's not running the whole loop.
#include <iostream>
#include <string>
#include <random>
#include <ctime>
using namespace std;
int main()
{
cout << "the battle of ninjas and skeletons" << endl;
// battle properties
char turn = 'N';
int numNinja;
int numSkeleton;
int startNinja = numNinja; //numNinja is uninitialised, so startNinja would be uninitialised too
int startSkeleton = numSkeleton; //numSkeleton is uninitialised, so startSkeleton would be uninitialised too
//the user is inputting the number of skeletons so i thought it wasn't suppose to be initialized
while((numNinja > 0) && (numSkeleton > 0)) {
if(turn = 'N') { //warning: suggest parentheses around assignment used as truth value [-Wparentheses]
ninjaAttackChance; //warning: statement has no effect [-Wunused-value]
can you please explain what the warnings means?
i don't understand why 'ninjaAttackChance' doesn't have an affect when i've initialized it like this:
float ninjaAttackChance = attack(randomEngine);
> the user is inputting the number of skeletons so i thought it wasn't suppose
> to be initialized
code executes from top to bottom. You use `numSkeleton' before you read the value from the user.
> //warning: suggest parentheses around assignment used as truth value
= is assignment
== is comparison
There you are assigning 'N' to turn.
> i don't understand why 'ninjaAttackChance' doesn't have an affect when
> i've initialized it like this:
Go yell "42" in the middle of the street and tell me what effect did it have.
You are not doing any operation there.