|
 |
|
 |
07-09-2003, 04:28 PM
|
#1 (permalink)
|
|
Techno Rat
Join Date: Jan 2003
Location: San Diego
Posts: 559
|
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
|
|
|
07-09-2003, 08:06 PM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
|
maybe because it should be
int main()
instead of
main()
|
|
|
07-09-2003, 09:48 PM
|
#3 (permalink)
|
|
Non-profit Techie
Join Date: Dec 2002
Location: Mesa AZ
Posts: 76
|
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. 
|
|
|
07-09-2003, 09:50 PM
|
#4 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
you're missing a closing parenthesis somewhere. probably in your while() loop
|
|
|
07-09-2003, 09:54 PM
|
#5 (permalink)
|
|
Techno Rat
Join Date: Jan 2003
Location: San Diego
Posts: 559
|
LOL, I was missing a closing { just like joe_bruin said.
Thanks guys,
Ilya.
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
|
|
|
07-09-2003, 10:08 PM
|
#6 (permalink)
|
|
Techno Rat
Join Date: Jan 2003
Location: San Diego
Posts: 559
|
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
|
|
|
07-10-2003, 04:23 AM
|
#7 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
|
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.
|
|
|
07-10-2003, 07:02 AM
|
#8 (permalink)
|
|
Techno Rat
Join Date: Jan 2003
Location: San Diego
Posts: 559
|
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
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 10:53 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|