compile error, someone please pioint out my mistake
hey guys, im in my first c programming class, and this si my first program using functions. heres the code i wrote, and the compiler error i get is:
:In function 'main':
:87: parse error before 'int'
heres the code.. please, reply to me by email as son as you can find the error, or my AIM. [edited by sunburnt]
/* this program keeps track of batting statistics for baseball,
it reads the nameof the batter,the overall numberof hits, at-bats,
and homeruns. it willreadthe numbers for all of these in a loop, then
it will stop at -1 hits. the output will be the batter's name,
the totals for all 3, and the computed batting average shown to 3
decimal places.
program written by Aaron Russell */
#include <stdio.h>
/* declare variables for main method */
int numbHits, numbAtbats, numbHomeruns;
float battingAverage;
/* this function reads in all the data to be inputed, including
Hits, at-bats, and homeruns */
void inputs( int *hits, int *atbats, int *homeruns ) {
/* declare and initialize stat counters, a for hits,
b for at bats, c for homeruns */
int a=0, b=0, c=0;
/* input the overall no. of hits, at-bats, and
homeruns */
printf( "Enter overall hits, at-bats, and homeruns:\n" );
scanf( "%d%1d%1d, hits, atbats, homeruns" );
/* do/while loop to enter in the additional batting
statistics, and end when -1 is entered for hits */
do {
/* while loop to check for input errors, make sure no.
of hits and at-bats always exceeds no. of homeruns */
while ( c <= a && a <= b && c <= b ) {
/* counter action adds additonal hits, at-bats, and
homeruns to overall stats for each variable */
hits += a;
atbats +=b;
homeruns +=c;
/* input the no. of hits, at-bats, and
homeruns */
printf( "Enter hits, at-bats, and homeruns:\n" );
scanf( "%d%1d%1d, &a, &b, &c" );
} /* end while */
} while ( a != -1 ); /* end do/while */
} /* end inputs function */
/* function average calculates batting average */
float average( int hits, int atbats ) {
/* declare bataverage as floating point */
float bataverage;
/* calculate the batting average */
bataverage = (float) hits / atbats;
/* return to indicate what average calculates */
return bataverage;
} /* end function average */
/* main function incorporates the two previous functions to output
a single line taht summarizes the data inputed for that player, and
his batting average */
int main () {
/* variable to store the name */
char name;
/* input the name of the batter */
printf( "Enter name:\n" );
scanf( "%c, &name" );
/* intitialize ints and float for displaying hits, at-bats,
homeruns*/
int numbHits = 0;
int numbAtbats = 0;
int numbHomeruns = 0;
float battingAverage;
/* generate input data using function inputs */
inputs( &numbHits, &numbAtbats, &numbHomeruns );
/* calculate average using function average */
battingAverage = average( numbHits, numbAtbats );
/* Prints the summary line that has the results for Name, hits,
at-bats, homeruns, and batting average */
printf( "%c has %d hits, %d at-bats, %d home runs, and a batting
average of %1.3f\n", name, numbHits, numbAtbats, numbHomeruns, battingAverage );
return 0;
} /* end main function */