#include <iostream>
#include <iomanip.h>
#include <time.h>
int rollDice();
int main ()
{
enum Status{CONTINUE, WON, LOST};
int sum, myPoint;
Status gameStatus;
srand(time(NULL));
sum=rollDice();
switch(sum)
{
case 7: case 11:
gameStatus=WON;
break;
case 2: case 3: case 12:
gameStatus=LOST;
break;
default:
gameStatus=CONTINUE;
myPoint=sum;
cout << "My point is "<<myPoint<<endl;
break;
}
while(gameStatus==CONTINUE)
{
sum=rollDice();
if(sum==myPoint)
gameStatus=WON;
else
if(sum==7)
gameStatus=LOST;
}
if(gameStatus=WON)
cout<<"Player won!"<<endl;
else
cout<<"Player lost!"<<endl;
}
There is no header called iomanip.h
, it should be just iomanip
cout
and endl
is located inside the std namespace so you have to specify by writing std::cout
, or using the using
directive.
if(gameStatus=WON)
should be if(gameStatus==WON)
.
You also have to define the function rollDice()
.
Can you say it more clearly, like how to define the function rollDice()?
I'm using gcc on a mac. It reports error if I write "iomanip", correct if I write "iomanip.h".
Thank you Peter.
I am using the compatible version of gcc for mac os 10.6.8.