Whats wrong with my code? formula? or data type?

//I always receive a negative value for the final grade. I dnt know

//if theres something with the data type I used or maybe with the //formula =(( I made this in Turbo C. Please help me. This has no //errors. The only problem is that i always receive a negative final grade

#include<stdio.h>

#include<conio.h>

#define p printf

#define s scanf

void main()

{

double q1 = 0, q2 = 0, aveq = 0, lab1 = 0, lab2 = 0,

avelab = 0, asgn1 = 0, asgn2 = 0, aveasgn = 0, attd = 0, exam = 0,

cs = 0, grade = 0;

p("#######################################################\n\n");

p(" ***COMPUTERIZED GRADING SYSTEM*** \n\n");

p(" ################################################### \n\n");

p("______________________Requirements______________________\n\n");

p("--QUIZZES--\t --LABORATORIES--\t--ASSIGNMENTS-- \n\n");

p(" QUIZ#01\t\t LAB#1 \t ASSIGN#1 \n\n ");

p(" QUIZ#02\t\t LAB#2 \t ASSIGN#2 \n\n ");

p("\n");

p("\n");

p("--ATTENDANCE--\t\t--EXAM-- \n\n");

p(" TOTAL ATT. FINAL EXAM \n\n");

p("\n\n\n");

p("FORMULA:\n\n");

p("GRADE: (Class Standing * 0.5) + (Final Exam * 0.5)\n\n");

p("Class Standing:(Ave Quiz) * 0.6 + (Ave Lab) * 0.3 +\n\n") ;

p(" (Ave Assgn)*0.05 + (Att * 0.5)\n\n");

p("\n\n\n");

p(" _____________Press ENTER to START_____________");

getch();

clrscr();

p(" ***COMPUTERIZED GRADING SYSTEM*** \n\n");

p("######################################################\n\n");

p(" *______________Enter the Requirements_____________*\n\n");

p(" Quizzes : \n\n");

p(" Quiz#01 : ");

s("%d",q1);

p("\n\n");

p(" Quiz#02 : ");

s("%d",q2);

p("\n\n");

p(" LABORATORIES : \n\n");

p(" LAB#01 : ");

s("%d",lab1);

p("\n\n");

p(" LAB#02 : ");

s("%d",lab2);

p("\n\n");

p(" ASSIGNMENTS : \n\n");

p(" ASGN#01 : ");

s("%d",asgn1);

p("\n\n");

p(" ASGN#02 : ");

s("%d",asgn2);

p("\n\n");

p(" ATTENDANCE : ");

s("%d",attd);

p("\n\n");

p(" EXAM : ");

s("%d",exam);

p("\n\n");

aveq = (q1 + q2)/2;

avelab = (lab1 + lab2)/2;

aveasgn = (asgn1 + asgn2)/2;

cs = (aveq)* 0.6 + (avelab) * 0.3 + (aveasgn) * 0.05 + (attd) * 0.5;

grade = (cs) * 0.5 + (exam) * 0.5;

p(" *_________________________RESULT_____________________*\n\n");

p(" --COMPUTERIZED GRADE-- --REMARK--\n\n");

p(" ");

p("%d",grade);

if (grade < 75)

p(" \t\tFAILED");

else

p(" \t\tPASSED");

getch();

}

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    1. You are scanning for integers (%d) but placing the result into doubles.

    2. You need to pass the address of the variable into which you want to scan the values, i.e., scanf("%lf",&q1) -- note the ampersand.

Still have questions? Get your answers by asking now.