Error Message...

Got an error message (commented below) any help would be appreciated
thx


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[])
{
int currentNumber=0;
int computerMove;
int humanMove;
int test;
int turnCounter=0;
cout<<"Let’s Play 21! Rules: Each player can either add 1, 2, or 3 to the current number which starts at zero. The goal is to force your opponent to say 21. If that happens, you win! Good luck...I'll go first...";

currentNumber=(1+srand(time(NULL))%3);//"Invalid Operands to a bunary expression 'Void and Int'"
cout<<currentNumber;
(turnCounter++);

cout<<" Your turn! Enter 1, 2, or 3.";

cin>>humanMove;
currentNumber=(currentNumber+humanMove);
(turnCounter++);

if (currentNumber==4){
computerMove=(1+(rand()%3));
currentNumber=currentNumber+computerMove;
cout<<currentNumber;}

if (currentNumber==2){
computerMove=2;
currentNumber=4;
cout<<currentNumber;
turnCounter++;}

if (currentNumber==3){
computerMove=1;
currentNumber=4;
cout<<currentNumber;
turnCounter++;}




}
srand() and rand() are 2 different functions. You are attempting to use srand() as if it were rand():

You want to do this:

 
currentNumber=(1+rand()%3); // <- don't use srand here 


srand is used to initialize the random number generator. You should call it once at the start of your program to ensure you get a different string of random numbers every time the program is run.

1
2
3
4
int main(int argc, const char * argv[])
{
    srand(time(NULL));  // <- do this once at the start of main
    //... 
Topic archived. No new replies allowed.