Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-13-2003, 06:00 PM   #1 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
Angry not again

Alrite... Runing slackware 8.1 with gcc 3.2.2 the following code wont compile..whats wrong?

Code:
/* Craps */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int rollDice(void);

main()
{
   int gameStatus, sum, myPoint;

   srand(time(NULL));
   sum = rollDice();            /* first roll of the dice */

   switch(sum) {
      case 7: case 11:          /* win on first roll */
         gamestatus = 1;
         break;
      case 2: case 3: case 12:  /* lose on first roll */
         gameStatus = 2;
         break;
      default:                  /* remember point */
         gameStatus = 0;
         myPoint = sum;
         printf("Point is %d\n", myPoint);
         break;
   }

   while (gameStatus == 0) {    /* keep rolling */
      sum = rollDice();

      if (sum == myPoint)       /* win by making point */
         gameStatus = 1;
      else
         if (sum == 7)          /* lose by rolling 7 */
            gameStatus = 2;
   }

   if (gameStatus == 1)
      printf("Player wins\n");
   else
      printf("Player loses\n");

   return 0;
}

int rollDice(void)
{
   int die1, die2, workSum;

   die1 = 1 + (rand() % 6);
   die2 = 1 + (rand() % 6);
   workSum = die1 + die2;
   printf("Player rolled %d + %d = %d\n", die1, die2, workSum);
   return workSum;
}
Here is the error message

[SHELL][ ~/C/:17:59:15]>> fig5_10.c: In function `main':
> fig5_10.c:17: `gamestatus' undeclared (first use in this function)
> fig5_10.c:17: (Each undeclared identifier is reported only once
> fig5_10.c:17: for each function it appears in.)[/SHELL]

Anyone?

Ilya.
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 03-13-2003, 06:04 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
In case 7 you have a typo: gamestatus.
Should be: gameStatus.

Compare with the int declaration
There might be more but I didnt check

- Val -
Valmont is offline   Reply With Quote
Old 03-13-2003, 08:03 PM   #3 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
Quote:
Originally posted by Valmont
In case 7 you have a typo: gamestatus.
Should be: gameStatus.

Compare with the int declaration
There might be more but I didnt check

- Val -
Y got it..

Thanks Val...

Ilya.
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 05:31 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting