diff --git a/README.md b/README.md index 2f9d18e..f5f29ee 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,21 @@ # Dart Programs - - ## Program 1: Display Personal Information + Write a Dart program using variables to display your name, age, school, and a hobby. Print it in one logical sentence. ## Program 2: Perform Mathematical Operations with Functions + Write a Dart program that performs two mathematical operations using functions. ## Program 3: Determine Grade Based on Marks + Write a Dart program to determine the grade based on a student's marks. The program should print out the appropriate grade according to the following criteria: + - If the marks are greater than 85, print "Excellent". - If the marks are between 75 and 85 (inclusive), print "Very Good". - If the marks are between 65 and 75 (inclusive), print "Good". - If the marks are below 65, print "Average". + +All the best. diff --git a/controlflow.dart b/controlflow.dart index d6dc466..2b011dd 100644 --- a/controlflow.dart +++ b/controlflow.dart @@ -1,7 +1,35 @@ +// ## Program 3: Determine Grade Based on Marks +// Write a Dart program to determine the grade based on a student's marks. The program should print out the appropriate grade according to the following criteria: +// - If the marks are greater than 85, print "Excellent". +// - If the marks are between 75 and 85 (inclusive), print "Very Good". +// - If the marks are between 65 and 75 (inclusive), print "Good". +// - If the marks are below 65, print "Average". -## Program 3: Determine Grade Based on Marks -Write a Dart program to determine the grade based on a student's marks. The program should print out the appropriate grade according to the following criteria: -- If the marks are greater than 85, print "Excellent". -- If the marks are between 75 and 85 (inclusive), print "Very Good". -- If the marks are between 65 and 75 (inclusive), print "Good". -- If the marks are below 65, print "Average". +import 'dart:io'; + +void main() { + //prompt the user to enter an input + print("\nEnter your marks: \n"); + int? marks = int.parse(stdin.readLineSync()!); + print("\nYour scrore is: ${marks}"); + + /* + check marks between 1 and 100 + and print error message for marks + outside this range + */ + if (marks > 0 && marks <= 100) { + //check the grade + if (marks > 85) { + print("\nExcellent \n"); + } else if (marks > 75) { + print("\nVery Good \n"); + } else if (marks > 65) { + print("\nGood \n"); + } else { + print("\nAverage \n"); + } + } else { + print("\nERROR: Marks cannot be less than 1 or greater than 100. \n"); + } +} diff --git a/functions.dart b/functions.dart index 914640c..1c302f3 100644 --- a/functions.dart +++ b/functions.dart @@ -1,2 +1,32 @@ -## Program 2: Perform Mathematical Operations with Functions -Write a Dart program that performs two mathematical operations using functions. +// ## Program 2: Perform Mathematical Operations with Functions +// Write a Dart program that performs two mathematical operations using functions. +import 'dart:io'; + +void main() { + //prompt user to enter the fist number + print("\Enter the 1st number: \n"); + int? any1stNumber = int.parse(stdin.readLineSync()!); + + //prompt user to enter the second number + print("\Enter the 2nd number: \n"); + int? any2ndNumber = int.parse(stdin.readLineSync()!); + + //call the functions that implement the sum and the product + int sum = addTwoNums(any1stNumber, any2ndNumber); + int product = multiplyTwoNums(any1stNumber, any2ndNumber); + + //Print the numbers entered + print("\nYou have entered ${any1stNumber} and ${any2ndNumber}"); + + //print the SUM and the product of the two numbers + print("\nThe sum of ${any1stNumber} and ${any2ndNumber} is ${sum} "); + print("\nThe product of ${any1stNumber} and ${any2ndNumber} is ${product}\n"); +} + +int addTwoNums(num1, num2) { + return (num1 + num2); +} + +int multiplyTwoNums(num1, num2) { + return (num1 * num2); +} diff --git a/program1.dart b/program1.dart new file mode 100644 index 0000000..eb90998 --- /dev/null +++ b/program1.dart @@ -0,0 +1,13 @@ +// ## Program 1: Display Personal Information +// Write a Dart program using variables to display your name, age, school, and a hobby. +//Print it in one logical sentence. + +void main() { + String name = "Kipkorir"; + num age = 50; + String school = "PLP"; + String hobby = "Coding"; + + print( + "\nMy name is ${name}, aged ${age}, studying at ${school}. My hobby is ${hobby}.\n"); +}