News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Issues with formula

Started by michael1320, February 20, 2015, 01:24:25 AM

Previous topic - Next topic

michael1320

HI I am building a program that will take in assignment, quiz, exams, and final exams and calculate the percentage. The code is not complete so there are a couple things not operating. My percent's are not showing up for quizzes and exams and are not being called into my perc function.

#include <stdio.h>
#include <stdlib.h>


const int MAX = 100;
const int ASSIGN_TOTAL = 7, QUIZ_TOTAL = 3, EXAMS_TOTAL = 2;
const int ASSIGN_MAX = 100, QUIZ_MAX = 25, EXAMS_MAX = 100, FINAL_MAX = 100;


int main()
{
    char name[MAX];
    int assigns[ASSIGN_TOTAL], quizzes[QUIZ_TOTAL], exams[EXAMS_TOTAL], finalExam;
    double assignsMedian, assignsMean, assignsPerc;
    double quizzesMedian, quizzesMean, quizzesPerc;
    double examsMedian, examsMean, examsPerc, finalPerc, classPerc, classGrade;

    do
    {
        readName(name);

        fillArray(assigns, ASSIGN_TOTAL, "assignments");
        selectionSort(assigns, ASSIGN_TOTAL);
        assignsMedian = findMedian(assigns, ASSIGN_TOTAL);
        assignsMean = findMean(assigns, ASSIGN_TOTAL);
        assignsPerc = calcPercentage(assigns, ASSIGN_TOTAL, ASSIGN_MAX);


        fillArray(quizzes, QUIZ_TOTAL, "quizzes");
        selectionSort(quizzes, QUIZ_TOTAL);
        quizzesMedian = findMedian(quizzes, QUIZ_TOTAL);
        quizzesMean = findMean(quizzes, QUIZ_TOTAL);
        quizzesPerc = calcPercentage(quizzes, QUIZ_TOTAL, QUIZ_MAX);


        fillArray(exams, EXAMS_TOTAL, "exams");
        selectionSort(exams, EXAMS_TOTAL);
        examsMedian = findMedian(exams, EXAMS_TOTAL);
        examsMean = findMean(exams, EXAMS_TOTAL);
        examsPerc = calcPercentage(exams, EXAMS_TOTAL, EXAMS_MAX);


        //finalExam = readFinalScore();
        //finalPerc = calcFinalPercentage(finalExam, FINAL_MAX);

        classPerc = calcClassPerc(assignsPerc, quizzesPerc, examsPerc, finalPerc);
        //classGrade = calcGrade(assignsPerc, quizzesPerc, examsPerc, finalPerc);

        //displayResults(name, classPerc, classGrade,
                       //assignsPerc, quizzesPerc, examsPerc, finalPerc,
                       //assignsMean, quizzesMean, examsMean,
                       //assignsMedian, quizzesMedian, examsMedian);

    }while(goAgain());

    return 0;
}
//**************************************************************************************//

int readName(int s)

{
    printf("\nName: ");
    scanf(" %s", s);
}

//**************************************************************************************//

int fillArray(int x[], int num, int k)

{
    int i;

    for(i = 1; i <= num; i++)
    {
        printf("\nScore for %s %d: ", k, i);
        scanf(" %d", &x);
    }
}

//**************************************************************************************//

int goAgain()

{
    char answer;

    printf("\nWould you like to calculate another set of scores (Y/N) ");
    scanf(" %c", &answer);

    if(answer != 'n' && answer != 'N')
       {
           return answer;
       }
    else
        {
            return 0;
        }
}

//**************************************************************************************//

int selectionSort(int myScore[], int total)

{  int  lim,
        hole;

   for ( lim = 1 ; lim < total ; lim++ )      //Credit Tim Rolfe
   {  int save = myScore[lim];              //Lecture 02-12-2015 Chapter 23 Sorting Arrays

      for ( hole = lim ;

            hole > 0 && save < myScore[hole-1] ;
            hole-- )
      {  myScore[hole] = myScore[hole-1];  }

      myScore[hole] = save;
   }
}

//**************************************************************************************//

int findMedian(int myPapery[], int num)

{
    int middle1, middle2, i;
    float median, median2;

    middle1 = num / 2;
    middle2 = (num/2)-1;

    if ((num % 2) == 0)
    {
        median = (myPapery[middle1] + myPapery[(middle2)]);
        median = median /2;
    }
    else
    {
        median = myPapery[middle1 + 0] / 1;
    }
return median;
}

//**************************************************************************************//

int findMean(int myPaperx[], int num)

{
    int j, sum, sum1;

    for(sum = j = 0; j < num; j++)
    {
        sum += myPaperx[j];
        sum1 = sum / num;
    }

    return sum1;
}

//**************************************************************************************//

int calcPercentage(int papers[], int total, int max)

{
    int y, sum = 0, sum1 = 0;

    sum1 = (total * max);
    printf("TOTAL: %d\n", sum1);
    for(sum = y = 0; y <= total; y++)
    {
        sum += papers[y];
    }
    printf(" SUM: %d\n", sum);
    printf(" PERC: %d\n", (sum/sum1)*100);



}

stahta01

Please read the CB Rules. http://forums.next.codeblocks.org/index.php/topic,9996.0.html

I saw no question in your post; so, you might wish to post one after reading the rules.

Tim S.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

michael1320

Quote from: michael1320 on February 20, 2015, 01:24:25 AM
HI I am building a program that will take in assignment, quiz, exams, and final exams and calculate the percentage. The code is not complete so there are a couple things not operating. My percent's are not showing up for quizzes and exams and are not being called into my perc function.

Can anyone take a quick look and see if there is anything popping out that may be wrong.

Thanks Michael

stahta01

Quote from: michael1320 on February 20, 2015, 03:11:16 AM
Quote from: michael1320 on February 20, 2015, 01:24:25 AM
HI I am building a program that will take in assignment, quiz, exams, and final exams and calculate the percentage. The code is not complete so there are a couple things not operating. My percent's are not showing up for quizzes and exams and are not being called into my perc function.

Can anyone take a quick look and see if there is anything popping out that may be wrong.

Thanks Michael

The main problem seems to be you can NOT read the rules and follow them.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Jenna

Quote from: stahta01 on February 20, 2015, 03:38:29 AM
Quote from: michael1320 on February 20, 2015, 03:11:16 AM
Quote from: michael1320 on February 20, 2015, 01:24:25 AM
HI I am building a program that will take in assignment, quiz, exams, and final exams and calculate the percentage. The code is not complete so there are a couple things not operating. My percent's are not showing up for quizzes and exams and are not being called into my perc function.

Can anyone take a quick look and see if there is anything popping out that may be wrong.

Thanks Michael

The main problem seems to be you can NOT read the rules and follow them.

Tim S.

So this topic gets locked and the OP warned !