#ifndef __FUNC__
#define __FUNC__
#include <time.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
usingnamespace std;
int points=3;
int enemypoints=3;
bool compare_plays(string a, string b)
{
if ((a=="Rock" && b=="Scissors") || (a=="Paper" && b=="Rock") || (a=="Scissors" && b=="Paper"))
{
returntrue;
}
elsereturnfalse;
}
void game_func(string c, string p)
{
// Playing rules!
if (c == p)
{
cout << "Enemy: " << p << "------------" << "Player: " << c << endl;
cout << "IT WAS A TIE!" << endl;
}
elseif (c!=p)
{
cout << "Enemy: " << p << "------------" << "Player: " << c << endl;
compare_plays(c, p);
if (compare_plays(c,p))
{
enemypoints-=1;
cout << "ENEMY LOST A POINT AND NOW HAS " << enemypoints << " left!" << endl;
}
else
{
points-=1;
cout << "YOU LOST A POINT AND NOW HAVE " << points << " left!" << endl;
}
}
}
#endif
I get no errors, but the problem seems to be in the main.cpp file. I am having trouble with the rand() conditional (where it generates a random number between 0 and 3 and then based on that tells if variable "play" is rock paper or scissors). Thanks in advance
First: Line 12 must be before line 7 (srand() only once!)
Second: Line13: Since you add 1 to the value you will get always values > 1 (and hence never "Rock")