วันเสาร์ที่ 21 กันยายน พ.ศ. 2556

Condition (Medium)


Exercise 1: Write a Java program that determines a student’s grade.

The program will read three types of scores(quiz, mid-term, and final scores) and determine the grade based on the following rules:
-if the average score >=90% =>grade=A
-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F
See the example output below:
Quiz score: 80
Mid-term score: 68
Final score: 90
Your grade is B.
Solution:

void setup() {
  showGrade();
}

void showGrade() {

  float quiz_score = 80; 
  float mid_score = 68; 
  float final_score = 90; 
  float avg = (quiz_score+mid_score+final_score)/3;

  if (avg>=90) {
    println("Your grade A.");
  }
  else if (avg>=70 && avg<90) {
    println("Your grade B.");
  }
  else if (avg>=50 && avg<70) {
    println("Your grade C.");
  }
  else if (avg<50) {
    println("Your grade F.");
  }
  else {
    println("Invalid");
  }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น