Skip to content

Instantly share code, notes, and snippets.

@bookwarmdev
Last active November 6, 2021 14:43
Show Gist options
  • Save bookwarmdev/85b979f9f4efb0413331a7dd1bfbd25e to your computer and use it in GitHub Desktop.
Save bookwarmdev/85b979f9f4efb0413331a7dd1bfbd25e to your computer and use it in GitHub Desktop.
#1 Capstone Project -2
import 'dart:io';
void main() {
// Problem Statement #
// Given the final percentage a student has gotten at the end of a semester,
// you need to write a program that decides if the student has passed or failed the semester.
// If the percentage is higher than or equal to 60, the student has passed the semester.
// If the percentage is lower than 60, the student has failed the semester.
// However, the percentage is not the only thing that determines if a student has passed or failed.
// A student does not pass if their score is 5 points below the class average.
// For instance, if the average class score is 70, the student must have a minimum score of 65 to pass.
// If the average class score is 50, the student still needs a score of 60 to pass based on our first condition.
// int studentScore, averageClassScore;
try {
stdout.write('Enter the student percentage here : ');
int? studentPercent = int.parse(stdin.readLineSync()!);
if (studentPercent < 0 || studentPercent > 100) {
print('------------- ERROR ALERT -------------');
print('Your input score must not be greater than 100 nor lesser than 0');
stdout.write('Enter the student percentage here : ');
studentPercent = int.parse(stdin.readLineSync()!);
} else {
stdout.write('Enter the average class score here : ');
int averageClassScore = int.parse(stdin.readLineSync()!);
stdout.write('Enter the student score here : ');
int? studentScore = int.parse(stdin.readLineSync()!);
final int passPoint = averageClassScore - 5;
// this condition check is the student score is more than 60 for he/she to pass the semester.
if (studentPercent >= 60 && studentScore >= passPoint) {
// this condition check if the average class score is 50, and the student still score of 60 to pass.
if (averageClassScore <= 60 && studentScore >= 60) {
print('This student has passed this semester');
// this condition check if the average class score is more than 50 and if the student score up to the pass mark.
} else if (averageClassScore >= 60 && studentScore >= passPoint) {
print('This student has passed this semester');
} else {
print('This student has failed this semester');
}
} else {
print('This student has failed this semester');
}
}
} catch (e) {
print('------------- INVALID INPUT -------------');
print('Score must be a valid integer value');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment