I'm having some difficulties understanding how functions work in a program. In the case of this function:
Code:
typedef enum {lost, won, go_on} status;
//more functions
status turnStatus (int rollNum, int total, int pt)
// function: turnStatus
// pre: rollNum is 1 or more, total is valid (2 to 12)
// post: returns the status of the game (won, lost, or go_on)
{
if (rollNum == 1) // first roll of the dice
if (total == 2 || total == 3 || total == 12)
return lost;
else if (total == 7 || total == 11)
return won;
else
return go_on;
else
if (total == 7)
return lost;
else if (total == pt)
return won;
else
return go_on;
}
How are the variables actually defined? What makes up "total", etc? I see checks for equality, but Im used to seeing something like total = (x * y) or something like that to indicate exactly where total came from. Is this tied in with the precondition somehow? Also, in this particular program, the main does not declare these variables. they only are used here.
Any info is appreciated
Thanks,
crazychile