### hi, i need help with my coding because the calculation of the cgpa doesnt appear :(

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283`` `````` #include #include using namespace std; struct gpa { string grade[4]; int credit[4], point[4]; } student; double pointcal(string grade); void calculate_gpa(); void print(); int main() { cout<<"\nENTER GRADE FOR THE FOLLOWING SUBJECT:-"<> student.grade[0]; cout<<"SUBJECT CREDIT :"; cin >> student.credit[0]; cout<<"INOVATION AND ORGANIZATION (SFES1322) : " ; cin>> student.grade[1]; cout<<"SUBJECT CREDIT :"; cin >> student.credit[1]; cout<<"BASIC MINERALOGI (SGES1274) :"; cin>> student.grade[2]; cout<<"SUBJECT CREDIT :"; cin >> student.credit[2]; cout<<"BASIC MINERALS, ROCKS AND FOSSIL (SGES1275) :"; cin>> student.grade[3]; cout<<"SUBJECT CREDIT :"; cin >> student.credit[3]; cout<<"BIOCOMPUTING (SHES1603) : "; cin>> student.grade[4]; cout<<"SUBJECT CREDIT :"; cin >> student.credit[4]; print(); } double pointcal(string grade) { { if (grade=="A" || grade=="a") { return 4.0; } else if (grade=="A-" || grade=="a-") { return 3.75; } else if (grade=="B+" || grade=="b+") { return 3.5; } else if (grade=="B" || grade=="b") { return 3.25; } else if (grade=="B-" || grade=="b-") { return 3.0; } else if (grade=="C+" || grade=="c+") { return 2.75; } else if (grade=="C" || grade=="c") { return 2.5; } else if (grade=="C-" || grade=="c-") { return 2.25; } else if (grade=="D" || grade=="d") { return 2.0; } else if (grade=="E" || grade=="e") { return 1.5; } else if (grade=="F" || grade=="f") { return 1.25; } else { return 0; } } } void calculate_gpa() { double gpa_s; double total_point = 0; double total_credit = 0; int i; for (i=0; i<7; i++) { student.point[i] = pointcal(student.grade[i]) * student.credit[i]; total_point += student.point[i]; total_credit += student.credit[i]; } gpa_s = total_point / total_credit; cout<<"GPA: "<
Pick an indentation style. https://en.wikipedia.org/wiki/Indentation_style
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495`` ``````#include #include using namespace std; struct gpa { string grade[4]; int credit[4], point[4]; } student; double pointcal(string grade); void calculate_gpa(); void print(); int main() { cout << "\nENTER GRADE FOR THE FOLLOWING SUBJECT:-" << endl; cout << "LOGIC AND CRITICAL THINKING (SFES1101) :"; cin >> student.grade[0]; cout << "SUBJECT CREDIT :"; cin >> student.credit[0]; cout << "INOVATION AND ORGANIZATION (SFES1322) : "; cin >> student.grade[1]; cout << "SUBJECT CREDIT :"; cin >> student.credit[1]; cout << "BASIC MINERALOGI (SGES1274) :"; cin >> student.grade[2]; cout << "SUBJECT CREDIT :"; cin >> student.credit[2]; cout << "BASIC MINERALS, ROCKS AND FOSSIL (SGES1275) :"; cin >> student.grade[3]; cout << "SUBJECT CREDIT :"; cin >> student.credit[3]; cout << "BIOCOMPUTING (SHES1603) : "; cin >> student.grade[4]; cout << "SUBJECT CREDIT :"; cin >> student.credit[4]; print(); } double pointcal(string grade) { { if (grade == "A" || grade == "a") { return 4.0; } else if (grade == "A-" || grade == "a-") { return 3.75; } else if (grade == "B+" || grade == "b+") { return 3.5; } else if (grade == "B" || grade == "b") { return 3.25; } else if (grade == "B-" || grade == "b-") { return 3.0; } else if (grade == "C+" || grade == "c+") { return 2.75; } else if (grade == "C" || grade == "c") { return 2.5; } else if (grade == "C-" || grade == "c-") { return 2.25; } else if (grade == "D" || grade == "d") { return 2.0; } else if (grade == "E" || grade == "e") { return 1.5; } else if (grade == "F" || grade == "f") { return 1.25; } else { return 0; } } } void calculate_gpa() { double gpa_s; double total_point = 0; double total_credit = 0; int i; for (i = 0; i < 7; i++) { student.point[i] = pointcal(student.grade[i]) * student.credit[i]; total_point += student.point[i]; total_credit += student.credit[i]; } gpa_s = total_point / total_credit; cout << "GPA: " << gpa_s << endl; } void print() { cout << endl; cout << "\nLOGIC AND CRITICAL THINKING (SFES1101) :" << student.grade[0]; cout << "\nINOVATION AND ORGANIZATION (SFES1322) : " << student.grade[1]; cout << "\nBASIC MINERALOGI (SGES1274) :" << student.grade[2]; cout << "\nBASIC MINERALS, ROCKS AND FOSSIL (SGES1275) :" << student.grade[3]; cout << "\nBIOCOMPUTING (SHES1603) :" << student.grade[4] << endl; calculate_gpa(); }``````

> cin >> student.credit[4];
...
> for (i = 0; i < 7; i++)
...
Your array is only 4 elements, so your valid subscripts are 0 to 3 only.
Accessing outside your arrays will just get you trouble.

For a slightly different take on this using an array for the subject names, consider (without input validation):

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475`` ``````#include #include #include constexpr const char* const subnames[] {"LOGIC AND CRITICAL THINKING (SFES1101)", "INOVATION AND ORGANIZATION (SFES1322)", "BASIC MINERALOGI (SGES1274)", "BASIC MINERALS, ROCKS AND FOSSIL(SGES1275)", "BIOCOMPUTING (SHES1603)"}; constexpr size_t NoSubs {std::size(subnames)}; struct Subject { std::string grade; int credit {}; int point {}; }; double pointcal(const std::string& grade); void calculate_gpa(Subject subjects[NoSubs]); void print(Subject subjects[NoSubs]); int main() { Subject subjects[NoSubs] {}; std::cout << "\nEnter grade and credit for the following subjects:-\n"; for (size_t s = 0; s < NoSubs; ++s) { std::cout << subnames[s] << "\nGrade: "; std::cin >> subjects[s].grade; std::cout << "Credit: "; std::cin >> subjects[s].credit; } print(subjects); } double pointcal(const std::string& grade) { if (grade == "A" || grade == "a") return 4.0; else if (grade == "A-" || grade == "a-") return 3.75; else if (grade == "B+" || grade == "b+") return 3.5; else if (grade == "B" || grade == "b") return 3.25; else if (grade == "B-" || grade == "b-") return 3.0; else if (grade == "C+" || grade == "c+") return 2.75; else if (grade == "C" || grade == "c") return 2.5; else if (grade == "C-" || grade == "c-") return 2.25; else if (grade == "D" || grade == "d") return 2.0; else if (grade == "E" || grade == "e") return 1.5; else if (grade == "F" || grade == "f") return 1.25; else return 0; } void calculate_gpa(Subject subjects[NoSubs]) { double total_point {}; double total_credit {}; for (size_t i = 0; i < NoSubs; ++i) { subjects[i].point = pointcal(subjects[i].grade) * subjects[i].credit; total_point += subjects[i].point; total_credit += subjects[i].credit; } std::cout << "\nGPA: " << total_point / total_credit << '\n'; } void print(Subject subjects[NoSubs]) { std::cout << '\n'; for (size_t i = 0; i < NoSubs; ++i) std::cout << std::left << std::setw(46) << subnames[i] << ": " << subjects[i].grade << '\n'; calculate_gpa(subjects); }``````

Topic archived. No new replies allowed.