What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Please Wait

Honorary Poster
Joined
Jan 25, 2017
Messages
554
Reaction score
222
Age
19
, Last edited:
Code:
#include<stdio.h>
#include<conio.h>
int act,quiz,att,Assignment,pro,exam,grade,prelim;
main()
{
    printf("PRELIM:\n");
    printf("Activity:");
    scanf("%d",&act);
    printf("Assignment:");
    scanf("%d",&Assignment);
    printf("Quiz:");
    scanf("%d",&quiz);
    printf("Attendance:");
    scanf("%d",&att);
    printf("Project:");
    scanf("%d",&pro);
    printf("Exam Result:");
    scanf("%d",&exam);
 
    grade=(act+Assignment+quiz+att+pro+exam)/6;
 
    printf("your prelim grade is:%d",grade);


     if(grade>=98)
 
    printf("\n1.00 Excellent");
    
    else if(grade>=95)
 
    printf("\n1.25 Excellent");
 
    else if(grade>=92)
 
    printf("\n1.50 Very good");
    
   else if(grade>=89)
 
    printf("\n1.75 Very good");
        
        
else if(grade>=86)
 
    printf("\n2.00 Good");
            
else if(grade>=83)
 
    printf("\n2.25 good");
                
else if(grade>=80)
 
    printf("\n2.50 good");

else if(grade>=77)
 
    printf("\n2.75 satisfactory");

 
else if(grade>=75)
 
    printf("\n3.00 passed");
                            
else

    printf("\n5.00 Failed");
 
 
    printf("\nMIDTERM");
    printf("\nActivity:");
    scanf("%d",&act);
    printf("Assignment:");
    scanf("%d",&Assignment);
    printf("Quiz:");
    scanf("%d",&quiz);
    printf("Attendance:");
    scanf("%d",&att);
    printf("Project:");
    scanf("%d",&pro);
    printf("Exam Result:");
    scanf("%d",&exam);
 
    grade=(act+Assignment+quiz+att+pro+exam)/6;
    printf("Your Midterm grade:%d",grade);


    if(grade>=98)
 
    printf("\n1.00 Excellent");
    
    else if(grade>=95)
 
    printf("\n1.25 Excellent");
 
    else if(grade>=92)
 
    printf("\n1.50 Very good");
    
   else if(grade>=89)
 
    printf("\n1.75 Very good");
        
        
else if(grade>=86)
 
    printf("\n2.00 Good");
            
else if(grade>=83)
 
    printf("\n2.25 good");
                
else if(grade>=80)
 
    printf("\n2.50 good");

else if(grade>=77)
 
    printf("\n2.75 satisfactory");

 
else if(grade>=75)
 
    printf("\n3.00 passed");
                            
else

    printf("\n5.00 Failed");
 
     printf("Final\n");
    printf("Activity:");
    scanf("%d",&act);
    printf("Assignment:");
    scanf("%d",&Assignment);
    printf("Quiz:");
    scanf("%d",&quiz);
    printf("Attendance:");
    scanf("%d",&att);
    printf("Project:");
    scanf("%d",&pro);
    printf("Exam Result:");
    scanf("%d",&exam);
 
    grade=(act+Assignment+quiz+att+pro+exam)/6;
 
    printf("your Final grade is:%d",grade);
 
      if(grade>=98)
 
    printf("\n1.00 Excellent");
    
    else if(grade>=95)
 
    printf("\n1.25 Excellent");
 
    else if(grade>=92)
 
    printf("\n1.50 Very good");
    
   else if(grade>=89)
 
    printf("\n1.75 Very good");
        
        
else if(grade>=86)
 
    printf("\n2.00 Good");
            
else if(grade>=83)
 
    printf("\n2.25 good");
                
else if(grade>=80)
 
    printf("\n2.50 good");

else if(grade>=77)
 
    printf("\n2.75 satisfactory");

 
else if(grade>=75)
 
    printf("\n3.00 passed");
                            
else

    printf("\n5.00 Failed");
 
 


 
    return 0;
}


nalilito ako kung pano sya kusang yung prelim grade midterm grade at final grade sa baba pag tapos ma input nung lahat ng grade tapos kusa na sya makukuha yung average nya
 

choppork

Addict
, Last edited:
Ang problema sa code mo sir ay yung variables. Dapat ang ginawa mo, kada isang grade ay iba't iba.

Bale meron ka dapat:
int prelims_grade, midterms_grade, finals_grade, total_grade;

And sila ang gagamitin mo. So bale sa Prelims for example, sa prelims_grade mo isa-save ung result.
prelims_grade=(act+Assignment+quiz+att+prô+exam)/6;

So sa mga conditionals, babaguhin mo rin. Imbis na if (grade>=98), magiging if (prelims_grade >= 98) and so on. So bale ganon din gagawin mo sa midterms at finals.

Tapos sa huli. Gawa ka ng something like:
total_grade = (prelims_grade + midterm_grade + finals_grade) / 3;

Tapos iprint mo sya. Kung gusto mo lagyan mo rin nung mga if (grade>=98).

Kung ako sa'yo gagawa ako ng panibagong function para don sa mahabang if else na 'yon since paulit ulit sya ginagamit sa code mo. Good luck~

Edit: So kapag sinunod mo 'yung codes ko, pwede mo rin iprint 'yung grades ng prelims, midterms, at finals sa baba bago mo ipakita 'yung total grade.

Edit: Bale parang ganito, kulang pa sya pero andito na 'yung general idea. Pakipansin mo rin sir 'yung ginawa ko sa mga pangalan, kinumpleto ko sila kasi okay lang naman na mahaba ang variable names. Mas malinaw pati kung kumpleto. Tapos, ung spacing din inayos ko. And yung sa capital letters sa mga "Very Good" at "good". Yung iba ay hindi naka-capital sa'yo so inayos ko rin. Ginawa ko ring float yung values kasi pwedeng magkaroon ng grade sa activity ng 98.66% or something na may decimals. Tapos ginawan ko rin ng function. Kung tutuusin nga ung pagkuha nung grades sa quizzes, activities, etc. pwede ring gawing function kasi paulit ulit sya. Not sure kung andon na kayo sa topic na 'yon. Pwede nating baguhin ung codes later kung wala pa. Tanggalin natin ung function.
C++:
#include<stdio.h>
#include<conio.h>

float activity, quiz, attendance, assignment, project, exam, prelims_grade, midterms_grade, finals_grade;

void equivalentGrade(float grade) {
    printf("\nEquivalent to: ");
   
    if (grade>=98)

        printf("1.00 - Excellent");
   
    else if(grade>=95)

        printf("1.25 - Excellent");

    else if(grade>=92)

        printf("1.50 - Very Good");
   
    else if(grade>=89)

        printf("1.75 - Very Good");
       
    else if(grade>=86)
   
        printf("2.00 - Good");
               
    else if(grade>=83)
   
        printf("2.25 - Good");
                   
    else if(grade>=80)
   
        printf("2.50 - Good");
   
    else if(grade>=77)
   
        printf("2.75 - Satisfactory");
   
   
    else if(grade>=75)
   
        printf("3.00 - Passed");
                               
    else
   
        printf("5.00 - Failed");
}

int main(void)
{
    printf("PRELIM:\n");
    printf("Activity: ");
    scanf("%f", &activity);
    printf("Assignment: ");
    scanf("%f", &assignment);
    printf("Quiz: ");
    scanf("%f", &quiz);
    printf("Attendance: ");
    scanf("%f", &attendance);
    printf("Project: ");
    scanf("%f", &project);
    printf("Exam Result: ");
    scanf("%f", &exam);

    prelims_grade= (activity + assignment + quiz + attendance + project + exam) / 6;

    printf("Your prelims grade is: %f", prelims_grade);
    equivalentGrade(prelims_grade);
   
    return 0;
}
Result:
1565714763709.png
 

homer_simpson

Honorary Poster
, Last edited:
Dapat subukan mo i-implement using loop, para kung sakali madag-dagan o mabasan ng term(s), update mo lang yung char* array, eg const char *semester[] = { "PRELIM", "MIDTERM", "FINAL" };
Tapos, gawa ka ng loop where it will process all the terms, eg:

Code:
    for (int i=0; i<num_of_terms; i++) {
        show_gpa(semester[i]);
    }
Try mo ito:

Code:
#include <conio.h>
#include<stdio.h>

int get_score(const char *term);
int show_gpa(const char *term, int score);

int main(void) {
    const char *semester[] = { "PRELIM", "MIDTERM", "LAST TERM" };
    size_t num_of_terms = sizeof(semester)/sizeof(semester[0]);
    int final_gpa=0;
    for (int i=0; i<num_of_terms; i++) {
        final_gpa+=show_gpa(semester[i], get_score(semester[i]));
    }
    printf("FINAL GPA: %d\n", final_gpa/num_of_terms);
    return 0;
}

int get_score(const char *term) {
    int act, quiz, att, Assignment, exam, pro, prelim, grade=0;
    printf("--%s--\n", term);
    printf("Activity: ");
    scanf("%d", &act);
    printf("Assignment: ");
    scanf("%d", &Assignment);
    printf("Quiz: ");
    scanf("%d", &quiz);
    printf("Attendance: ");
    scanf("%d", &att);
    printf("Project: ");
    scanf("%d", &pro);
    printf("Exam Result: ");
    scanf("%d", &exam);
    grade=(act+Assignment+quiz+att+pro+exam)/6;
    printf("Your %s grade is: %d\n", term, *(&grade));
    return grade;
}

int show_gpa(const char *term, int grade) {
    printf("RESULT: ");
    if(grade>=98)
         printf("1.00 Excellent");
    else if(grade>=95)
         printf("1.25 Excellent: %d\n");
    else if(grade>=92)
         printf("1.50 Very good\n");
    else if(grade>=89)
        printf("1.75 Very good\n");
    else if(grade>=86)
        printf("2.00 Good\n");
    else if(grade>=83)
        printf("2.25 good\n");
    else if(grade>=80)
        printf("2.50 good\n");
    else if(grade>=77)
        printf("2.75 satisfactory\n");
    else if(grade>=75)
        printf("3.00 passed\n");
    else
        printf("5.00 FAILED!\n");
    printf("\n");
    return grade;
}
 

choppork

Addict
Dapat subukan mo i-implement using loop, para kung sakali madag-dagan o mabasan ng term(s), update mo lang yung char* array, eg const char *semester[] = { "PRELIM", "MIDTERM", "FINAL" };
Tapos, gawa ka ng loop where it will process all the terms, eg:

Code:
    for (int i=0; i<num_of_terms; i++) {
        show_gpa(semester[i]);
    }
Try mo ito:

Code:
#include <conio.h>
#include<stdio.h>

int get_score(const char *term);
void show_gpa(const char *term);

int main(int argc, char *argv[]) {
    const char *semester[] = { "PRELIM", "MIDTERM", "FINAL" };
    size_t num_of_terms = sizeof(semester)/sizeof(semester[0]);
    for (int i=0; i<num_of_terms; i++) {
        show_gpa(semester[i]);
    }
    return 0;
}

int get_score(const char *term) {
    int act, quiz, att, Assignment, exam, prô, prelim, grade=0;
    printf("--%s--\n", term);
    printf("Activity: ");
    scanf("%d", &act);
    printf("Assignment: ");
    scanf("%d", &Assignment);
    printf("Quiz: ");
    scanf("%d", &quiz);
    printf("Attendance: ");
    scanf("%d", &att);
    printf("Project: ");
    scanf("%d", &prô);
    printf("Exam Result: ");
    scanf("%d", &exam);
    //grade=([I](&act)+[/I](&Assignment)+[I](&quiz)+[/I](&att)+[I](&prô)+[/I](&exam))/6;
    grade=(act+Assignment+quiz+att+prô+exam)/6;
    printf("Your %s grade is: %d\n", term, *(&grade));
    return grade;
}

void show_gpa(const char *term) {
    int grade = get_score(term);
    printf("RESULT: ");
    if(grade>=98)
         printf("1.00 Excellent");
    else if(grade>=95)
         printf("1.25 Excellent: %d\n");
    else if(grade>=92)
         printf("1.50 Very good\n");
    else if(grade>=89)
        printf("1.75 Very good\n");
    else if(grade>=86)
        printf("2.00 Good\n");
    else if(grade>=83)
        printf("2.25 good\n");
    else if(grade>=80)
        printf("2.50 good\n");
    else if(grade>=77)
        printf("2.75 satisfactory\n");
    else if(grade>=75)
        printf("3.00 passed\n");
    else
        printf("5.00 FAILED!\n");
    printf("\n");
}

XD, eto na pinakaokay na solution logic-wise. Ang kulang nalang ay yung last part na magsosolve nung average nung prelims, midterms, at finals para magkaroon ng final grade. Haha.
 

homer_simpson

Honorary Poster
, Last edited:
In-update ko ng konti yung code para kasali yung pinaka final gpa. Tapos renamed yung final term into last term para hindi confusing.

One more comment. Yung conditionals na:
Code:
...
else if(grade>=95)

    printf("\n1.25 Excellent");

    else if(grade>=92)
...
hanggat maari dapat, i-specify natin yung floor at ceiling. For example, the value 95 satisfies both conditions. In fact, it also matches 95 and above for that matter. It can cause some weird, hard to track issues. So dapat ganito:
Code:
...
else if(grade>=92 && grade<95)
...
just to specify that it only catches values between 92-94.
 

choppork

Addict
In-update ko ng konti yung code para kasali yung pinaka final gpa. Tapos renamed yung fina term into last term para hindi confusing.
Baka gusto mo ring gawing finalgpa/num_of_terms instead of dividing it lang sa 3 since you mentioned na scalable sya kapag nagdagdag ng panibagong term.
 

choppork

Addict
Na-update ko nga din sa num_of_terms accordingly .
Seems like hindi na nag-effort si OP dun sa example mo sa 95 score since magtr-true naman sya doon sa unang if and magkakaroon na ng result. Kumbaga, "naka-if else" naman. Idk kung paano magkakaroon ng weird error. Care to share? Mukhang okay sakin ung logic
 

homer_simpson

Honorary Poster
Seems like hindi na nag-effort si OP dun sa example mo sa 95 score since magtr-true naman sya doon sa unang if and magkakaroon na ng result. Kumbaga, "naka-if else" naman. Idk kung paano magkakaroon ng weird error. Care to share? Mukhang okay sakin ung logic
Tutoo yung sinabi mo. Pero naka-depende sa strict ordering ng conditionals yung magiging resulta. Yung reasoning ko kasi is always catch any potential issue kung posible. To me it eliminates yung gotcha later on.
 

choppork

Addict
Tutoo yung sinabi mo. Pero naka-depende sa strict ordering ng conditionals yung magiging resulta. Yung reasoning ko kasi is always catch any potential issue kung posible. To me it eliminates yung gotcha later on.
... which is logic. But ehh, either one works fine.
 

homer_simpson

Honorary Poster
Refactored the number of activities (Activity, Assignment, Quiz, Attendance, etc):
Code:
#include<conio.h>
#include<stdio.h>

int get_score(const char *term);
int show_gpa(const char *term, int score);

int main(int argc, char *argv[]) {
    const char *semester[] = { "PRELIM", "MIDTERM", "LAST TERM" };
    size_t num_of_terms = sizeof(semester)/sizeof(semester[0]);
    int final_gpa=0;
    for (int i=0; i<num_of_terms; i++) {
        final_gpa+=show_gpa(semester[i], get_score(semester[i]));
    }
    printf("\n\nFINAL GPA: %d\n", final_gpa/3);
    return 0;
}

int get_score(const char *term) {
    int grade=0, score=0;
    const char *activities[] = { "Activity", "Assignment", "Quiz", "Attendance", "Project", "Exam" };
    size_t num_of_activities = sizeof(activities)/sizeof(activities[0]);
    printf("--%s--\n", term);
    for (int i=0; i<num_of_activities; i++){
        printf("%s: ", activities[i]);
        scanf("%d", &score);
        grade+=score;
    }
    grade=grade/num_of_activities;
    printf("Your %s grade is: %d\n", term, grade);
    return grade;
}

int show_gpa(const char *term, int grade) {
    printf("RESULT: ");
    if(grade>=98)
         printf("1.00 Excellent");
    else if(grade>=95)
         printf("1.25 Excellent");
    else if(grade>=92)
         printf("1.50 Very good\n");
    else if(grade>=89)
        printf("1.75 Very good\n");
    else if(grade>=86)
        printf("2.00 Good\n");
    else if(grade>=83)
        printf("2.25 good\n");
    else if(grade>=80)
        printf("2.50 good\n");
    else if(grade>=77)
        printf("2.75 satisfactory\n");
    else if(grade>=75)
        printf("3.00 passed\n");
    else
        printf("5.00 FAILED!\n");
    printf("\n");
    return grade;
}
 

choppork

Addict
Refactored the number of activities (Activity, Assignment, Quiz, Attendance, etc):
Code:
#include<conio.h>
#include<stdio.h>

int get_score(const char *term);
int show_gpa(const char *term, int score);

int main(int argc, char *argv[]) {
    const char *semester[] = { "PRELIM", "MIDTERM", "LAST TERM" };
    size_t num_of_terms = sizeof(semester)/sizeof(semester[0]);
    int final_gpa=0;
    for (int i=0; i<num_of_terms; i++) {
        final_gpa+=show_gpa(semester[i], get_score(semester[i]));
    }
    printf("\n\nFINAL GPA: %d\n", final_gpa/3);
    return 0;
}

int get_score(const char *term) {
    int grade=0, score=0;
    const char *activities[] = { "Activity", "Assignment", "Quiz", "Attendance", "Project", "Exam" };
    size_t num_of_activities = sizeof(activities)/sizeof(activities[0]);
    printf("--%s--\n", term);
    for (int i=0; i<num_of_activities; i++){
        printf("%s: ", activities[i]);
        scanf("%d", &score);
        grade+=score;
    }
    grade=grade/num_of_activities;
    printf("Your %s grade is: %d\n", term, grade);
    return grade;
}

int show_gpa(const char *term, int grade) {
    printf("RESULT: ");
    if(grade>=98)
         printf("1.00 Excellent");
    else if(grade>=95)
         printf("1.25 Excellent");
    else if(grade>=92)
         printf("1.50 Very good\n");
    else if(grade>=89)
        printf("1.75 Very good\n");
    else if(grade>=86)
        printf("2.00 Good\n");
    else if(grade>=83)
        printf("2.25 good\n");
    else if(grade>=80)
        printf("2.50 good\n");
    else if(grade>=77)
        printf("2.75 satisfactory\n");
    else if(grade>=75)
        printf("3.00 passed\n");
    else
        printf("5.00 FAILED!\n");
    printf("\n");
    return grade;
}
Last na hirit na siguro:
good -> Good,
satisfactory -> Satisfactory,
passed -> Passed

Tsaka spacing don sa printf's sa mga if statements.
 

choppork

Addict
Yup, good practice. Kahapon, walang pumansin sa post ni TS. Ngayon naman, andyan na 'yung pinakang okay na solution, haha. Gulat siguro si TS pag gising nyan mamaya.
 

homer_simpson

Honorary Poster
Tingin ko kasi, kelangan lang best practice at tamang approach sa problem-solving.

Pero nagtataka lang ako, bakit C? By the way, scanf is really dangerous. It is prone to buffer overflow. Walang bounds checking. So yung solution natin, is ok lang assuming that the user won't input anything nasty. Anyway, practice lang muna, so ok lang.
 

choppork

Addict
Tingin ko kasi, kelangan lang best practice at tamang approach sa problem-solving.

Pero nagtataka lang ako, bakit C? By the way, scanf is really dangerous. It is prone to buffer overflow. Walang bounds checking. So yung solution natin, is ok lang assuming that the user won't input anything nasty. Anyway, practice lang muna, so ok lang.
I mean, yeah. Posible nga rin na mag-input ng number na lampas sa 100 na grade, so.. Haha. Marami pang pwedeng iimprove.
 

Please Wait

Honorary Poster
Salamat sa mga tumulong mga paps malaking tulong to.....di pa kasi na rurun ng maayos yan kaya di ko pa tlga pinapalitan yung mga capital tsaka mga small letters.😅😅...tsaka else if pala po tlga topic namin😂😂😂😂pero salmat parin haha
 

choppork

Addict
Salamat sa mga tumulong mga paps malaking tulong to.....di pa kasi na rurun ng maayos yan kaya di ko pa tlga pinapalitan yung mga capital tsaka mga small letters.😅😅...tsaka else if pala po tlga topic namin😂😂😂😂pero salmat parin haha
Hahaha. Overkill 'yung solution. Bigyan ka namin maya ng para lang sa else if muna. Sabi ko na nga ba't wala pa kayo sa function, kasi noong nagcollege ako eh ni hindi manlang kami umabot sa functions, hahahaha
 

Please Wait

Honorary Poster
Hahaha. Overkill 'yung solution. Bigyan ka namin maya ng para lang sa else if muna. Sabi ko na nga ba't wala pa kayo sa function, kasi noong nagcollege ako eh ni hindi manlang kami umabot sa functions, hahahaha
Hahahaha onga eh ....di na sakop ng utak ko mga solution nyo😂😂😂ibang level na haha
 

Trending Topics

Trending On This Forum

Unanswered Topics

Top