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 07-09-2003, 04:28 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
Error

I keep getting this error but dont know why.

Here is the code:

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

int roll_dice(void);

main()
{

  int gameStatus, sum, point;
	
	srand(time(NULL));
  	sum = roll_dice();

 	switch(sum) {
	
	case 7: case 11:
	gameStatus = 1;
	break;
	
	case 2: case 3: case 12:
	gameStatus = 2;
	break;

	default:
	gameStatus = 0;
	point = sum;
	printf("Point is %d\n", point);
	break; 
}
	
	while(gameStatus==0) {
		sum = roll_dice();
	
	if (sum == point) {
		gameStatus = 1; }
	else
	
	if (sum == 7) {
		gameStatus = 2; }



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



	return 0;

}

int roll_dice(void)
{
  int die1, die2, dieSum;

  die1 = 1 + (rand() % 6 );
  die2 = 1 + (rand() % 6 );
  dieSum = die1 + die2;

	printf("You rolled %d + %d = %d/n", die1, die2, sum);
	
	return sum;

}
Here is the error from gcc:

[SHELL]
ilya@sig11:~$ gcc craps.c
craps.c: In function `main':
craps.c:69: syntax error at end of input
[/SHELL]

Anyone know the problem? BTW, line 69 is the last line after the final }

cheers,

Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 07-09-2003, 08:06 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
redhead is on a distinguished road
maybe because it should be
int main()
instead of
main()
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 07-09-2003, 09:48 PM   #3 (permalink)
DesertWolf
Non-profit Techie
 
DesertWolf's Avatar
 
Join Date: Dec 2002
Location: Mesa AZ
Posts: 76
DesertWolf is on a distinguished road
Send a message via AIM to DesertWolf
I am a little rusty on my C++ but first, redhead is right it should be int main, then I don't see a return statement for the main method,
Quote:
main()
{

int gameStatus, sum, point;

srand(time(NULL));
sum = roll_dice();

switch(sum) {

case 7: case 11:
gameStatus = 1;
break;

case 2: case 3: case 12:
gameStatus = 2;
break;

default:
gameStatus = 0;
point = sum;
printf("Point is %d\n", point);
break;
}
This is the end of your main method with no return 0;
You do have a return in the next section with the while statement, but it is not in you main(), I would say that you are missing a set of braces {} for your main() method,
BUt hey I might be wrong I havent delt with C++ in a while.
DesertWolf is offline   Reply With Quote
Old 07-09-2003, 09:50 PM   #4 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
you're missing a closing parenthesis somewhere. probably in your while() loop
joe_bruin is offline   Reply With Quote
Old 07-09-2003, 09:54 PM   #5 (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
LOL, I was missing a closing { just like joe_bruin said.

Thanks guys,

Ilya.
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 07-09-2003, 10:08 PM   #6 (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
Totally fixed it now except there is a logic error and I will look into it later as I am going to bed now. Its only 11:08 but whatever...


Night,


Ilya.
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 07-10-2003, 04:23 AM   #7 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
redhead is on a distinguished road
Code:
int roll_dice(void)
{
  int die1, die2, dieSum;

  die1 = 1 + (rand() % 6 );
  die2 = 1 + (rand() % 6 );
  dieSum = die1 + die2;

	printf("You rolled %d + %d = %d/n", die1, die2, sum);
	
	return sum;

}
should be
Code:
int roll_dice(void)
{
  int die1, die2, dieSum;

  die1 = 1 + (rand() % 6 );
  die2 = 1 + (rand() % 6 );
  dieSum = die1 + die2;

	printf("You rolled %d + %d = %d/n", die1, die2, dieSum);
	
	return dieSum;

}
But since that would give another error than logical error, you might have changed that already.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 07-10-2003, 07:02 AM   #8 (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 redhead
Code:
int roll_dice(void)
{
  int die1, die2, dieSum;

  die1 = 1 + (rand() % 6 );
  die2 = 1 + (rand() % 6 );
  dieSum = die1 + die2;

	printf("You rolled %d + %d = %d/n", die1, die2, sum);
	
	return sum;

}
should be
Code:
int roll_dice(void)
{
  int die1, die2, dieSum;

  die1 = 1 + (rand() % 6 );
  die2 = 1 + (rand() % 6 );
  dieSum = die1 + die2;

	printf("You rolled %d + %d = %d/n", die1, die2, dieSum);
	
	return dieSum;

}
But since that would give another error than logical error, you might have changed that already.
you are....CORRECT

I saw that but I was tired and decided screw it. Stupid me...
__________________
> 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is this error? john_tran Standard C, C++ 4 10-20-2004 08:30 PM
{perl} HTTP Error Code Response gty All Other Coding Languages 2 09-08-2004 11:09 AM
Error SQL-query in importing file infinite_root PHP 1 06-08-2004 05:17 AM
C++ compile error Amaranthine Standard C, C++ 5 05-05-2004 08:23 PM


All times are GMT -8. The time now is 10:53 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