Hi im just trying to make a simpel dice roll game which seems very hard because srand always generates the number 0 to me.
I also ask the user to type roll to roll his dices which i try check if he really does type roll.
this is my code:
#include <iostream>
#include <cstdlib>
using namespace std;
int random_integer;
int pcdice1;
int pcdice2;
int humdice1;
int humdice2;
int result (int a,int b)
{
int res;
res=a+b;
return(res);
}
int main()
{
srand((unsigned)time(0));
for (int i=0 ;i<100 ; i++){
int random_integer = (rand()%6)+1;
random_integer = pcdice1;
}
srand((unsigned)time(0));
for (int i=0 ;i<100 ; i++){
int random_integer = (rand()%6)+1;
random_integer = pcdice2;
}
int pcdiceres = result(pcdice1,pcdice2);
cout << "the computer throwed " << pcdice1 << " and \n" << pcdice2 << endl;
cout << "resulting in: "<< pcdiceres << endl << endl;
srand((unsigned)time(0));
for (int i=0 ;i<50 ; i++){
int random_integer = (rand()%6)+1;
random_integer = humdice1;
}
srand((unsigned)time(0));
for (int i=0 ;i<50 ; i++){
int random_integer = (rand()%6)+1;
random_integer = humdice2;
}
char humaninput[100];
cout << "its your turn to roll, type roll to roll the dices \n";
while (humaninput != "roll")
{
cin >> humaninput;
if (humaninput != "roll")
{
cout <<"please type roll to roll the dice anything else counts as invalid: \n";
}
}
int humdiceres = result(humdice1,humdice2);
cout << "you throwed " << humdice1 << " and \n" << humdice2 << endl;
cout << "resulting in: "<< humdiceres << endl;
cout << "Press enter to continue..." << endl;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
also the compiler seems to give the error that it forbids to compare pointers with integers