Home > Back-end >  My code runs with no errors but it runs only a section of the code (C Language)
My code runs with no errors but it runs only a section of the code (C Language)

Time:03-14

i´m trying to make an algorithm to find the weighted mean of a student's grades (from 0 to 10) which gets 4 inputs: name, grade1, grade2, grade3 in vs code:

#include <stdio.h>

int main()
{
  float grade1, grade2, grade3, weightedaverage;
  char studentname[50];

  printf("\nType the name of the student: ");
  fgets(studentname, 50, stdin);

  printf("\nType the first grade: ");
  scanf("%f", grade1);

  printf("\nType the second grade: ");
  scanf("%f", grade2);

  printf("\nType the third grade: ");
  scanf("%f", grade3);

  weightedaverage = (grade1 *2)   (grade2 *4)   (grade3 *6) / 12;
  // 

  printf("\nNAME: %s\nWEIGHTED AVERAGE: %f", studentname, weightedaverage);

  return(0);
}

Well, the problem is when i run, it only executes until the input of the first "type your first grade" line, and then it stops running, like it justs show after that the path of where the program is located. What am i doing wrong?

CodePudding user response:

Basic error, always use & in scanf scanf("%f", &grade3);

  • Related