- TS TS
- #21
Thanks po dito kunan ko lang po based yung code mo po maraming salamatC++:#include <iostream> #include <iomanip> #include <stdio.h> using namespace std; int students = 3; // student name, subject, remarks string sn[3], sub[3], rem; // version-safe declaration // prelim, midterm, endterm float pl[3], mt[3], et[3]; // version-safe declaration // ariths float sum; float avg; int main() { // counter for(int ctr = 0; ctr < students; ctr++) { cout << "Enter student name: "; getline(cin, sn[ctr]); cout << sn[ctr] << endl; cout << "Enter subject: "; getline(cin, sub[ctr]); cout << sub[ctr] << endl; cout << "Enter Prelim Grade: "; cin >> pl[ctr]; cout << "" << pl[ctr] << endl; // concat cout << "Enter Midterm Grade: "; cin >> mt[ctr]; cout << "" << mt[ctr] << endl; // concat cout << "Enter Endterm Grade: "; cin >> et[ctr]; cout << "" << et[ctr] << "\n\n"; // concat cin.ignore(); // unstream cin } cout << "Computing Data..." << "\n\n"; // notifier // frame template cout << setw(16) << "Student Name"; cout << setw(18) << "Subject"; cout << setw(20) << "Final Grade"; cout << setw(15) << "Remarks"; cout << endl; // separator for(int ctr = 0; ctr < students; ctr++) { // ariths sum = pl[ctr] + mt[ctr] + et[ctr]; avg = sum / (float) students; if (avg > 5) { rem = "PASSED"; } else { rem = "FAILED"; } cout << setw(10) << sn[ctr]; cout << setw(17) << sub[ctr]; cout << setw(13) << avg; cout << setw(10) << rem; cout << endl; // separator } }
eto version ko, working 'yan, hindi ako gumagamit ng setw() kaya baka may mali ako sa alignment.
kung gusto mo ma-calculate pati fraction (e.g. 16.667) , just use float data type sa calculation mo, pati sa container variable