Anyone willing to help a ANSI C novice 
Author Message
 Anyone willing to help a ANSI C novice


I am just starting to learn ANSI C and am having difficulty making a program
work. The program reads in 5 grades to an array then needs to add the grades
in a seperate function and output the result. The result is obviously wrong.
Any help is much aprecited.



Program follows---

int sum(int array[],int,int);/*Function prototype*/
int main(void)

int myarray[5];
int num1=0, num2=0;
int total;
printf("The sum is %d\n",total);
return 0;


int sum(int array2[],int n1,int n2)
 int sumresult;
 int sum,x,i;


 printf("Enter the grade: ");
 scanf("%d", &array2[i]);


 for (x=0;x<4;x++);
  sum = sum + array2[x];


 return sumresult;


Fri, 23 Aug 2002 03:00:00 GMT  
 Anyone willing to help a ANSI C novice
Thankyou very much, its much apreciated.

Fri, 23 Aug 2002 03:00:00 GMT  
 Anyone willing to help a ANSI C novice

Here, you read 5 elements into the array


> printf("Enter the grade: ");
> scanf("%d", &array2[i]);


And here, you only sum 4 of them.

> for (x=0;x<4;x++);
> {
>  sum = sum + array2[x];

> }

This sort of thing is why passing the array size as an argument would be a
good idea.  If for some reason you don't want to do that, using a #define
would be the next best thing.

Kenan Systems Corp., a wholly-owned subsidiary of Lucent Technologies

Fri, 23 Aug 2002 03:00:00 GMT  
 [ 4 post ] 

 Relevant Pages 

1. Anyone willing to help me learn arrays?

2. Anyone willing to help???

3. Help!!! Novice CS Advice

4. anyone willing to help an extreme (1st day) novice?

5. Newbie: separate big .cs file into small .cs files

6. Novice question: ANSI/VT100 printer?

7. urgent! anyone willing to help?

8. Some interesting novice questions from a novice guy

9. newbe/cs student, need help w/ code

10. Compiler error CS 1595 - Help

11. yes I am willing to

12. I'm willing to program for you.


Powered by phpBB® Forum Software