homework help 
Author Message
 homework help

I am currently taking an intro class. My latest hw assignment will not work
correctly.
After I enter the number of grades  to be processed, the program aborts.
Can anyone see the problem?
Thankyou for your help.
Erik

*****************************************************************************
//Header files
#include <stdio.h>
#include <conio.h>

//Variable Declarations
int row, num, passing, aboveAv;
float av, totGrades;
float grades[10];

//Function Prototypes
void Initialize();
void GetGrades();
void FindAverage();
void CountHighGrades();
void DisplayResults();

void main()
{
        clrscr();

        Initialize();
        GetGrades();
        FindAverage();
        CountHighGrades();
        DisplayResults();

        printf("\n\nPress any key to continue....");
        getch();
        return;

Quote:
}

//FunctionName: Initialize()
//Description:  Initializes program variables

void Initialize()
{
//initialize variables
        passing = 0;    
        num = 100;
        totGrades = 0.0;
        av = 0;
        aboveAv = 0;

// Prompt for and accept #of grades to be processed
// If # of grades exceeds 10, display error message and reprompt

    printf("Please enter the number of grades to be averaged [maximum 10]:");
                while (num > 10)
                {
                scanf("%i", &num);
                if (num > 10)
                printf("\nPlease enter a number less than 11:");
                }
return;

Quote:
}

//Function Name:        GetGrades
//Description:          Accept grade inputs

void GetGrades()
{
        row = 0;
        while(row < num)
        {
                printf("\nEnter grade #%i:  ", row+1);
                scanf("%f", &grades[row]);
                row = row + 1;
        }
        return;

Quote:
}

//Function name:        FindAverage
//Description:          Calculate the average grade

void FindAverage()
{
        row = 0;
        while (row < num)
        {
                totGrades = totGrades + grades[row];
                row = row + 1;
        }
        av = totGrades / num;
return;

Quote:
}

//Function name:        CountHighGrades
//Description:          Count the number of grades higher than the
//                      average and the number of passing grades.

void CountHighGrades()
{
        row = 0;
        while(row < num)
        {
                if(grades[row] > av)
                aboveAv = aboveAv + 1;

                if(grades[row] > 60.0)
                passing = passing + 1;
                row = row + 1;
        }
        return;

Quote:
}

//Function name:        DisplayResults
//Description:          Display the grades, average, # of passing grades
//                      and the # of grades higher than the average

void DisplayResults()
{
        printf("\n\nThe grades you entered were:  ");
        row = 0;
        while(row < num)
        {
                printf("%f     ", grades[row]);
                row = row + 1;
        }
        printf("\n\nThe average grade is %.2f", av);
        printf("\n\nThere are %i grades above the average.", aboveAv);
        printf("\n\nThere are %i passing grades.", passing);
return;

Quote:
}

--



Wed, 15 May 2002 03:00:00 GMT  
 homework help

Quote:

> I am currently taking an intro class. My latest hw assignment will
> not work correctly.  After I enter the number of grades to be
> processed, the program aborts.  Can anyone see the problem?

[snip]

This has already been answered in comp.lang.c.  When you want to ask
something in several newsgroups, crosspost.
--
Nils Goesche
----------------------------------------
Fatal Error # 0x155 : Windows not found.
(C)heer  (P)arty  (D)ance
--



Fri, 17 May 2002 03:00:00 GMT  
 homework help


 This is a public reply to your message posted:
 From group: comp.lang.c.moderated;  on Sat, 27 Nov 1999 08:54:36 GMT
 Concerning "homework help";

~ > I am currently taking an intro class. My latest hw assignment will not work
~ > correctly.
~ > After I enter the number of grades  to be processed, the program aborts.
~ > Can anyone see the problem?
~ > Thankyou for your help.
~ > Erik

  I compiled it (to an exe) and ran your program under Borland C++ 3.1.
  Worked fine.  (I did not try neg numbers etc.)

--
 Friar Broccoli

 Best programmer's & all purpose text editor: http://www.semware.com

 --------- I consider ALL arguments in support of my views ---------
--



Fri, 17 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Homework Help

2. homework help scanning info from disk?

3. I will pay for homework help !HELLLPPPP !!!HELLLPPPP !!!

4. HOMEWORK HELP, AGAIN!!

5. Homework Help --- Ordering Three Inputted Numbers

6. HOMEWORK HELP!

7. homework help(arrays + pointers)

8. a little homework help....

9. Payroll Processing Homework Help

10. HOMEWORK HELP!!

11. Homework help: Where do I start?

12. C homework help - Reward offered

 

 
Powered by phpBB® Forum Software