Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
40 changes: 34 additions & 6 deletions controlflow.dart
Original file line number Diff line number Diff line change
@@ -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");
}
}
34 changes: 32 additions & 2 deletions functions.dart
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions program1.dart
Original file line number Diff line number Diff line change
@@ -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");
}