Thread: C programming,very short question,accesing variable from other class

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    17

    C programming,very short question,accesing variable from other class

    Here is the link for my program, I want to access the average value which is located in grade.c (calculate_grade) class through driver.c (main function) but I don't know how to make "average" visible


    https://www.dropbox.com/sh/72501ycafg6u7e7/jv_zCC17aV

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Next time, post your code inline, not at the end of a link which isn't a link at all (in other words, far too much effort)
    Code:
    #include <stdio.h>
    #include "grade.h"
    #include "stats.h"
      
    char*letter_grade(int grade)
    {
        char*test ="N";
      
        if(grade>=0 && grade<=59)        test="F";
        else if(grade>=60 && grade<=69)  test="D";
        else if(grade>=70 && grade<=79)  test="C";
        else if(grade>=80 && grade<=89)  test="B";
        else if(grade>=90 && grade<=100) test="A";
        else                             test="N";
      
        return test;
    }
    char*calculate_grade(int array[])
    {
        int size = ARRAY_SIZE;
        int sum =0;
        int average;
        int i=0;
        for(; i<size; i++) sum=sum+array[i];
        average = AVERAGE (sum,size);
      
        return (letter_grade(average));
    }
    > I want to access the average value which is located in grade.c (calculate_grade) class through driver.c (main function) but I don't know how to make "average" visible
    Well it would be better if calculate_grade() just returned the average.
    driver.c can then call letter_grade(average) all by itself, AND have the average on hand as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-25-2012, 05:32 PM
  2. accesing a class's overloaded [] via a pointer
    By mnj in forum C++ Programming
    Replies: 4
    Last Post: 03-11-2004, 04:35 PM
  3. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  4. Simple Short Class Question
    By Travis Dane in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2002, 07:12 PM