fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. float score;
  6.  
  7. // รับคะแนนจากผู้ใช้
  8. cout << "กรุณากรอกคะแนน (0-100): ";
  9. cin >> score;
  10.  
  11. // ตรวจสอบคะแนนและตัดเกรด
  12. if (score >= 90 && score <= 100) {
  13. cout << "เกรด: A" << endl;
  14. } else if (score >= 80 && score < 90) {
  15. cout << "เกรด: B" << endl;
  16. } else if (score >= 70 && score < 80) {
  17. cout << "เกรด: C" << endl;
  18. } else if (score >= 60 && score < 70) {
  19. cout << "เกรด: D" << endl;
  20. } else if (score >= 0 && score < 60) {
  21. cout << "เกรด: F" << endl;
  22. } else {
  23. cout << "คะแนนไม่ถูกต้อง! กรุณากรอกคะแนนระหว่าง 0 ถึง 100." << endl;
  24. }
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.03s 25784KB
stdin
Standard input is empty
stdout
#include <iostream>
using namespace std;

int main() {
    float score;

    // รับคะแนนจากผู้ใช้
    cout << "กรุณากรอกคะแนน (0-100): ";
    cin >> score;

    // ตรวจสอบคะแนนและตัดเกรด
    if (score >= 90 && score <= 100) {
        cout << "เกรด: A" << endl;
    } else if (score >= 80 && score < 90) {
        cout << "เกรด: B" << endl;
    } else if (score >= 70 && score < 80) {
        cout << "เกรด: C" << endl;
    } else if (score >= 60 && score < 70) {
        cout << "เกรด: D" << endl;
    } else if (score >= 0 && score < 60) {
        cout << "เกรด: F" << endl;
    } else {
        cout << "คะแนนไม่ถูกต้อง! กรุณากรอกคะแนนระหว่าง 0 ถึง 100." << endl;
    }

    return 0;
}