# Student mark with average

Page 1 of 1

## 3 Replies - 1788 Views - Last Post: 21 November 2010 - 06:28 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=201294&amp;s=73074275931cbe844f99e8e707b98a60&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 c infant

Reputation: 0
• Posts: 3
• Joined: 13-November 10

# Student mark with average

Posted 21 November 2010 - 05:11 AM

Hi all,
I am having trouble picking which variables need manipulating to produce the average mark.All the rest of the code works as desired.I would gratelly appreciate any help you can give.

Here's what I have to date:
``` // Lab 4 Prob 1  Student mark with average
// Author c infant

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main ()  // main function heading

{

// declare variables
float average;
int numb=0,sum=0;
int counter=1;
int asgninit=0,asgnfinal=0;
int a1=0;

printf("Enter student number:");                //enter student number and scan for input
scanf("%d",&numb);

printf("Enter initial assignment number:");     //enter assignment number parameters and scan for input
scanf("%d",&asgninit);

printf("Enter final assignment number:");
scanf("%d",&asgnfinal);

printf("\n\nAssignment number\tMark out of 20\n============================================\n");

for (counter=asgninit;counter<=asgnfinal;counter++)    // for loop conditions

{

printf("%.1d\t\t\t\t",counter);
scanf("%d",&a1);

if(a1>=0 && a1<=20);                            // conditions of validity
else printf("Please note marks are between 0 & 20\n"),system("PAUSE");

}                                               // end loop

sum+=a1;

average=sum/;                   // calculate average and display answer
printf("Average mark:%d\n",average);

system("PAUSE");                              // Pause to view result

}                                             // End program
```

Is This A Good Question/Topic? 0

## Replies To: Student mark with average

### #2 aaa111

• D.I.C Regular

Reputation: 88
• Posts: 284
• Joined: 21-February 07

## Re: Student mark with average

Posted 21 November 2010 - 05:32 AM

Don't you think this statement:
```sum+=a1;
```

Should be inside of the for loop.If you put it outside of the loop only the last inputted number will be added to sum.
As for your average i think you should divide sum by numb.Also use %f specifier in the printf:
```printf("Average mark:%f\n",average);
```

### #3 c infant

Reputation: 0
• Posts: 3
• Joined: 13-November 10

## Re: Student mark with average

Posted 21 November 2010 - 05:58 AM

aaa111, on 21 November 2010 - 11:32 AM, said:

Don't you think this statement:
```sum+=a1;
```

Should be inside of the for loop.If you put it outside of the loop only the last inputted number will be added to sum.
As for your average i think you should divide sum by numb.Also use %f specifier in the printf:
```printf("Average mark:%f\n",average);
```

appreciate the input.your suggestion for bringing the sum statement worked , but the "sum" cannot be divided by "numb" because numb is being used as an input for the student id number.I have tried a few different variable names but they return nonsence answers.

### #4 newclearner

• D.I.C Regular

Reputation: 103
• Posts: 302
• Joined: 29-September 10

## Re: Student mark with average

Posted 21 November 2010 - 06:28 AM

system("pause") isn't considered a good programming habbit. Check out my signature to find out the reason and alternative.