Jump to content

help with program

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
marquis1431

marquis1431

    Newbie

  • Members
  • Pip
  • 2 posts
how do i keep track of the values entered so far so that i can get the average in the display grade function...all values entered so far total..?

#include <stdio.h>

#include <stdlib.h>


#define TRUE 1

#define FALSE 0

#define SENTINEL -1


int getGradeValue(int, int);

void displayGrade( int, char);

int makeLetterGrade(int*);

int sentinel_value_encounted(int *);

int main(void)

{

	char letter;	

        int value;  

while ( !sentinel_value_encounted(&value)){


//        printf("Enter a value, between 0 and 110, representing the\n");

//        printf("grade for the examination\n");

//        scanf("%d", &value);


	

	int value = getGradeValue(0,110);

	letter = makeLetterGrade(&value);

	displayGrade(value, letter);

        printf("Enter a value, between 0 and 110, representing the\n");

        printf("grade for the examination\n");

        scanf("%d", &value);

}


        printf("Enter a value, between 0 and 110, representing the\n");

        printf("grade for the examination\n");

        scanf("%d", &value);


	return EXIT_SUCCESS;

}

int getGradeValue(int mingrade, int maxgrade)

{


	int value;

//while ( !sentinel_value_encounted(&value)){


        printf("Enter a value, between 0 and 110, representing the\n");

        printf("grade for the examination\n");

        scanf("%d", &value);

if (0<= value <= 110)

	return (value);

else

{

        printf("Invalid grade\n");

}  

//        printf("Enter a value, between 0 and 110, representing the\n");

//        printf("grade for the examination\n");

//        scanf("%d", &value);


        return EXIT_SUCCESS;

}


int makeLetterGrade(int *value)

{ 

	int  a_max, a_min, b_max, b_min, c_max, c_min, f_max, f_min;

	char letter;

	char A;

	char B;

	char C;

	char F;

	char X;	

	

        printf("Enter max and min grade value for A\n");

        scanf("%d %d", &a_max, &a_min);


        printf("Enter max and min grade value for B\n");

        scanf("%d %d", &b_max, &b_min);


        printf("Enter max and min grade value for C\n");

        scanf("%d %d", &c_max, &c_min);


        printf("Enter max and min grade value for F\n");

        scanf("%d %d", &f_max, &f_min);


if (a_max>=*value&&*value>=a_min)

	letter = 'A';

else if (b_max>=*value&&*value>=b_min)

{

        letter = 'B';

}

else if (c_max>=*value&&*value>=c_min)

{

        letter = 'C';

}

else if (f_max>=*value&&*value>=f_min)

{

        letter = 'F';

}

else

{

        letter = 'X';

}

	return letter;

}

      

void displayGrade (int value, char letter)

{

        static int nscore = 0;

        int tscore;

	

        printf("The score of %d earned a grade of %c\n", value, letter);

        printf("%d score were entered so far.\n", ++nscore );

        printf("All scores entered so far total %d\n", tscore);

        printf("The average score is %d\n", tscore/nscore);

}   


int sentinel_value_encounted(int *value)

{

if  (*value != SENTINEL)

        return (FALSE);

else

        return (TRUE);

} 




#2
marquis1431

marquis1431

    Newbie

  • Members
  • Pip
  • 2 posts
okay maybe this will help.....if you have a loop that asks for the user to input a value and the loop doesn't end until the sentinal, how can you keep track of all the values entered and add them together?