i cant get average inthe row

This is a discussion on i cant get average inthe row within the C Programming forums, part of the General Programming Boards category; hi i really need help i try many thing and i cant get an average for a column can someone ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    i cant get average inthe row

    hi i really need help i try many thing and i cant get an average for a column can someone help me i need to hand this in today. thank you
    Sorry is column that i want not row
    Code:
    
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    
    int main()
    {
          
          
            char student[50][25];
       int marks[50][5];
       int rowtotal,rowavg;
       int i, j,x;
       int num = 0;
           printf("how many studen");
          scanf("%i",&x);
        if(x<=50) 
    {       
          
             for (i = 0; i < x; i++) 
             {
             printf("name => ");
    		 fflush(stdin);
             gets(student[i]);
         
                  
                         printf("marks for prg=>");  
    				     scanf("%d", &marks[i][0]);
    				     printf("marks for DGS=>"); 
    					 scanf("%d", &marks[i][1]);
    				     printf("marks for MTH=>"); 
    					 scanf("%d", &marks[i][2]);
    			     	  printf("marks for ECR=>"); 
    				   	 scanf("%d", &marks[i][3]);
    			     	  printf("marks for GED=>"); 
    					 scanf("%d", &marks[i][4]);
                     
     
             }                       
         
                 
          }
           printf("\nStudent\tPRG\tDGS\tMTH\tECR\tGED\n"); 
      
         for (i = 0; i < x; i++) {
         printf("%s", student[i]);
    
                      
                        printf("\t%d\t%d\t%d\t%d\t%d", marks[i][0],marks[i][1],marks[i][2],marks[i][3],marks[i][4]);
                    
                        printf("\n");
       }
         
    
    
    	rowtotal+=marks[1][i];
    	rowavg=rowtotal/x;
        printf("%i",rowavg);
          
              
          getch();
          
    }
    Last edited by mouse666666; 02-20-2010 at 12:07 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You need to put a rowTotal, inside your loop, like the one you're printing with.

    rowTotal = marks[i][0] + marks[i][1] + marks[i][2] ==> up to 4.
    Then you need to add a line of code to divide rowTotal, by 5 (because 0 through 4 is 5)

    rowAvg = rowTotal/5;

    would do.

    Then you need to print out or save that rowAvg, before the next rowAvg is calculated. Don't forget to re-set rowTotal and rowAvg variables to zero, before the next row, or you'll get wrong answers.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    i try that it didnt work

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    Quote Originally Posted by mouse666666
    i try that it didnt work
    Then you are doomed

    It may well be the case that you just implemented the idea wrongly. Post your current code. (Please indent your code. You should also change that use of gets() to say, fgets().)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    i dont want to be doomed that is why i need help

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    iam getting some garbage value why is that

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I can't tell without seeing your code. maybe you forgot to set the variables to zero before the addition?

    Post your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. background ascii color
    By dvsumosize in forum C Programming
    Replies: 0
    Last Post: 11-09-2009, 10:19 AM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 04:37 AM
  5. Is there a bug in this part of my algorithm for connect 4?
    By Nutshell in forum Game Programming
    Replies: 8
    Last Post: 04-28-2002, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21