Quotient function with multiple variables

Every time I compile and run and tries to test, it always give me 0.00 as the score.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#define p ;printf
#define s ;scanf

main()
{int a,b,c,d,w,x,y,z, sum=0, quotient //a,w = Written exam, b,x = Lab drill, c,y = Final Lab, d,z = Final Written Exam
	p("FINAL GRADE COMPUTATION\n");
	p("Please input raw and total items of Written Exam separated by '/'\n");
	s("%d / %d\n",&a,&w);
	p("Your Written Exam score is %.2f percent\n",quotient);
	p("Please input raw and total items of Lab drill separated by '/'\n");
	s("%d / %d\n",&b,&x);
	p("Your Lab Drill score is %.2f percent\n",quotient);
	p("Please input raw and total items of Final Lab separated by '/'\n");
	s("%d / %d\n",&c,&y);
	p("Your Final Lab score is %.2f percent\n",quotient);
	p("Please input raw and total items of Final Written Exam separated by '/'\n");
	s("%d / %d\n",&d,&z);
	p("Your Final Written Exam score is %.2f percent\n",quotient);
	sum = w + x + y + z // I do not know what to put here, but it should be the total of all areas
	
	p("Your FINAL GRADE is %d",sum);
}


Thank you in advance.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>

/* no. repeat NO
#define p ;printf
#define s ;scanf */

main()
{
    /* use comments to state only those things that can't be expressed in code
    int a,b,c,d,w,x,y,z, total_score=0, quotient //a,w = Written exam, b,x = Lab drill, c,y = Final Lab, d,z = Final Written Exam
    */
    puts( "FINAL GRADE COMPUTATION" );

    puts( "Please input raw and maximum scores of Written Exam separated by '/'" );
    int written_exam_score, written_exam_max ; // use variable names that convey meaning
    if( scanf( "%d / %d", &written_exam_score, &written_exam_max ) < 2 )
    {
        puts( "input failed" ) ;
        return 1 ;
    }
    if( written_exam_score < 0 || written_exam_max < written_exam_score )
    {
        puts( "invalid Written Exam score" ) ;
        return 1 ;
    }

    printf( "Your Written Exam score is %.2f percent\n", written_exam_score * 100.0 / written_exam_max );

    puts( "Please input raw and maximum scores of Lab drill separated by '/'" );
    int lab_drill_score, lab_drill_max ;
    if( scanf( "%d / %d", &lab_drill_score, &lab_drill_max ) < 2 )
    {
        puts( "input failed" ) ;
        return 1 ;
    }
    if( lab_drill_score < 0 || lab_drill_max < lab_drill_score )
    {
        puts( "invalid Lab drill score" ) ;
        return 1 ;
    }

    printf( "Your Lab Drill score is %.2f percent\n", lab_drill_score * 100.0 / lab_drill_max );

    puts( "Please input raw and maximum scores of Lab final separated by '/'" );
    int lab_final_score, lab_final_max ;
    if( scanf( "%d / %d", &lab_final_score, &lab_final_max ) < 2 )
    {
        puts( "input failed" ) ;
        return 1 ;
    }
    if( lab_final_score < 0 || lab_final_max < lab_final_score )
    {
        puts( "invalid Lab final score" ) ;
        return 1 ;
    }

    printf( "Your Lab final score is %.2f percent\n", lab_final_score * 100.0 / lab_final_max );

    puts( "Please input raw and maximum scores of Final exam separated by '/'" );
    int final_exam_score, final_exam_max ;
    if( scanf( "%d / %d", &final_exam_score, &final_exam_max ) < 2 )
    {
        puts( "input failed" ) ;
        return 1 ;
    }
    if( final_exam_score < 0 || final_exam_max < final_exam_score )
    {
        puts( "invalid Final exam score" ) ;
        return 1 ;
    }

    printf( "Your Final exam score is %.2f percent\n", final_exam_score * 100.0 / final_exam_max );

    const int total_score = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
    const int total_max = written_exam_max + lab_drill_max + lab_final_max + final_exam_max ;
    const double percentage = total_score * 100.0 / total_max ;
    printf( "\nyour overall score is %u / %u or %.2f %%\n", total_score, total_max, percentage ) ;
}
Hi JLBorges,

Thank you for this code, however, we are only limited to use the most basic coding without yet using codes other than those stated on my codes. If you have any other way around by just using those, I would very much appreciate it.
If and else can also be used.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>

main()
{
    /* use comments to state only those things that can't be expressed in code
    int a,b,c,d,w,x,y,z, total_score=0, quotient //a,w = Written exam, b,x = Lab drill, c,y = Final Lab, d,z = Final Written Exam
    */
    printf( "FINAL GRADE COMPUTATION\n" );

    printf( "Please input raw and maximum scores of Written Exam separated by '/'\n" );
    int written_exam_score, written_exam_max ; // use variable names that convey meaning
    scanf( "%d / %d", &written_exam_score, &written_exam_max ) ;
    printf( "Your Written Exam score is %.2f percent\n", written_exam_score * 100.0 / written_exam_max );

    printf( "Please input raw and maximum scores of Lab drill separated by '/'\n" );
    int lab_drill_score, lab_drill_max ;
    scanf( "%d / %d", &lab_drill_score, &lab_drill_max ) ;
    printf( "Your Lab Drill score is %.2f percent\n", lab_drill_score * 100.0 / lab_drill_max );

    printf( "Please input raw and maximum scores of Lab final separated by '/'\n" );
    int lab_final_score, lab_final_max ;
    scanf( "%d / %d", &lab_final_score, &lab_final_max ) ;
    printf( "Your Lab final score is %.2f percent\n", lab_final_score * 100.0 / lab_final_max );

    printf( "Please input raw and maximum scores of Final exam separated by '/'\n" );
    int final_exam_score, final_exam_max ;
    scanf( "%d / %d", &final_exam_score, &final_exam_max ) ;
    printf( "Your Final exam score is %.2f percent\n", final_exam_score * 100.0 / final_exam_max );

    const int total_score = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
    const int total_max = written_exam_max + lab_drill_max + lab_final_max + final_exam_max ;
    const double percentage = total_score * 100.0 / total_max ;
    printf( "\nyour overall score is %u/%u or %.2f %%\n", total_score, total_max, percentage ) ;
}
Hi again JLBorges,

Thank you so much for this. We're getting near!

Could you please explain to me the meaning of Const int and const double? I am not yet aware of this function. I only know int, float, char, and char[].

Would "sum" not possible?
> Could you please explain to me the meaning of Const int and const double?

The const in const int and const double indicates hat these objects can't be subsequently modified. Throughout their life-time, these const objects retain their original values (an attempt to assign to an object with a const-qualified type generates a compile-time error).


> Would "sum" not possible?

Yes, it would be possible. Use the name 'sum' instead of 'total_score' if you want to.
Thank you so much JL for your reply. I really appreciate it so much. I just have some clarifications.

The sum i mean is that can we actually define sum as the operation to be used like ''int sum=0'' instead of having const int and double? Cos I might gonna have hard time in explaining that with my professor. and its already our midterm. Hope you can help me again. I tried searching for its definition but I cant really understand what does it mean and I'm so sorry about that. Hope you could extend your patience. Thank you!
Last edited on
Yes, you could write:
1
2
int sum = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
printf( "\nyour overall score is %d \n", sum ) ;


Or:
1
2
3
int sum = 0 ;
sum = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
printf( "\nyour overall score is %d \n", sum ) ;
@Altis You could write lines 30-32 above
30
31
32
    const int total_score = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
    const int total_max = written_exam_max + lab_drill_max + lab_final_max + final_exam_max ;
    const double percentage = total_score * 100.0 / total_max ;


like this instead:
30
31
32
    int total_score = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
    int total_max = written_exam_max + lab_drill_max + lab_final_max + final_exam_max ;
    float percentage = total_score * 100.0 / total_max ;


That should conform to what you are allowed to use, "I only know int, float, char, and char[]".

Regarding sum, that's just a variable name. Use any you like. The ones used by JLBorges such as total_score are perhaps more meaningful, but it doesn't affect the outcome. It's just a good habit to learn to use names like that rather than for example a single letter such as a or b which don't help the human reader to understand the code.

Topic archived. No new replies allowed.