C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
another code problem Posted by Panasonic99 on 5 Aug 2005 at 5:12 PM
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* function main begins program execution */
int main()
{
long i; /* counter */
int j; /* counter */
int x; /* 1st dice */
int y; /* 1nd dice */
int sum[ 13 ] = { 0 };

/* the dice will be rolled 36 times */
int expected[ 13 ] = { 0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1};

srand ( time( NULL) ); /* random number */
for ( i = 1; i <= 3600; i++ ) {
x = 1 + rand() % 6;
y = 1+ rand() % 6;
++sum[ x + y };
}

printf( "%10s%10s%10s%10s\n", "Sum", "Total", "Expected", "Actual" );

/* shows actual rolling of dice */
for ( j = 2; j <= 12; j++ ) {
printf( "%10d%10d%9.3f%%%9.3f%%\n", j, sum[ j ], 100.0 * expected[ j ] / 36, 100.0 * sum[ j ] / 3600 );
} /* end for statement */

return 0; /* indicate program ended successfully */

} /* end main */



--------------
when I go to compile it I get this:
"fig619T.c", line 22.18: 1506-277 (S) Syntax error: possible missing ',' or ']'?
"fig619T.c", line 25.3: 1506-273 (E) Missing type in declaration of printf.
"fig619T.c", line 25.3: 1506-343 (S) Redeclaration of printf differs from previous declaration on line 263 of "/usr/include/stdio.h".
"fig619T.c", line 25.3: 1506-378 (I) Prototype for function printf cannot contain "..." when mixed with a nonprototype declaration.


and also, what line is line 25.3? where do I count from- the top?
thanks
Report
Re: another code problem Posted by pseudocoder on 5 Aug 2005 at 5:33 PM
: ++sum[ x + y }; <-- needs a closing ] not the }. It's *probably* the source of the other errors.
: }

:
: and also, what line is line 25.3? where do I count from- the top?
: thanks

Yep... dunno what the floating point value indicates though. :)
:
Report
Re: another code problem Posted by BitByBit_Thor on 7 Aug 2005 at 1:29 PM
: : ++sum[ x + y }; <-- needs a closing ] not the }. It's *probably* the source of the other errors.
: : }
:
: :
: : and also, what line is line 25.3? where do I count from- the top?
: : thanks
:
: Yep... dunno what the floating point value indicates though. :)
: :
:

Most likely character 3.

Greets...
Richard




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.