0

OK I need help figuring out why my code doesn't work like I want it to. I need it to calculate the weighted percentages of a student taking 4 quizzes, 2 midterms and a final exam. the final and quizzes are weighted 30% while the midterm is 40%. The problems I'm having are:

  1. The test/Midterm section of the code isn't accepting the fourth input; I would put 80 80 80 80, but the compiler wouldn't recognize the last input and calculate as is.
  2. The final exam portion only works if I put a zero after enter the two test/midterm inputs

I'm new to coding and any help would be appreciated (:

#include <stdio.h>

int main()
{
   int testOne,testTwo,testPoint,totTest;
    float percTest;
    printf("Enter you test grades:\n");
    scanf(" %d%d\n",&testOne,&testTwo);
    totTest=testOne+testTwo;
    printf("Your total grade points is: %d\n", totTest);
    testPoint=200;
    percTest=(totTest*.40)/testPoint *100;
    printf("Your percentage is %.1f%%\n", percTest);

    int quizOne,quizTwo,quizThree,quizFour,quizPoint,totQuiz;
    float percQuiz;
    printf("Enter you quiz grades:\n");
    scanf(" %d%d%d%d\n",&quizOne,&quizTwo,&quizThree,&quizFour);
    totQuiz=quizOne+quizTwo+quizThree+quizFour;
    printf("Your total quiz grade is %d\n", totQuiz);
    quizPoint=400;
    percQuiz=(totQuiz*.30)/quizPoint *100;
    printf("Your quiz percentage is %.1f%%\n", percQuiz);
    
    int examOne,examPoint;
    float percExam,finGrade;
    printf("Enter your exam grade:\n");
    scanf(" %d\n",&examOne);
    printf("Your total exam points is: %d\n", examOne);
    examPoint=100;
    percExam=(examOne*.30)/examPoint *100;
    printf("Your final exam grade is %.1f\n", percExam);
    
    finGrade=(percExam+percQuiz+percTest);
    printf("Your overall grade is %.1f%%\n", finGrade);
   

    return 0;
}
  • Don't put `\n` in `scanf` format strings. – Barmar Sep 17 '21 at 04:09
  • @Barmar I just want to say I Fking love you my dude. Been struggling with this for days and you saw it in a matter of seconds – Anthony Hatcher Sep 17 '21 at 04:14
  • 1
    The post title should describe your question or problem well enough so that readers get the gist of what it's about ("Problem with Java function" is not very descriptive). Keep it succinct. See: [How do I write a good title?](https://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title) – John Kugelman Sep 17 '21 at 04:19
  • You cannot use any input function correctly unless you ***check the return*** before attempting to use the variable filled by the input to determine whether the input succeeded or failed. – David C. Rankin Sep 17 '21 at 04:24

0 Answers0