3 Replies - 1788 Views - Last Post: 21 November 2010 - 06:28 AM Rate Topic: -----

#1 c infant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
// Date last modified 20/11/10 19:26



// include header files
#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);
     
                                                     // assignment and grade heading
     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  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • 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);

Was This Post Helpful? 1
  • +
  • -

#3 c infant  Icon User is offline

  • New D.I.C Head

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

Re: Student mark with average

Posted 21 November 2010 - 05:58 AM

View Postaaa111, 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.
Was This Post Helpful? 0
  • +
  • -

#4 newclearner  Icon User is offline

  • D.I.C Regular

Reputation: 103
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1