Skip to content

Instantly share code, notes, and snippets.

@renso3x
Created March 4, 2026 04:07
Show Gist options
  • Select an option

  • Save renso3x/581e6cb48980a62bd2d467d63ffe0009 to your computer and use it in GitHub Desktop.

Select an option

Save renso3x/581e6cb48980a62bd2d467d63ffe0009 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.31;
contract Activity_4 {
/**
Temperature Checker
Make a function that will tell if the temperature is freezing point or boiling point.
Grade Evaluator
Make a function that will return a grade based on a score.
90 and above → “A”
80–89 → “B”
70–79 → “C”
Below 70 → “F”
**/
function tempChecker(uint temp) public pure returns (string memory) {
if (temp >= 90) {
return "A";
} else if (temp < 90 && temp >= 80) {
return "B";
} else if (temp < 80 && temp >= 70) {
return "C";
} else {
return "F";
}
}
/**
Speed Checker
Make a function that checks if a driver is overspeeding.
Note: 100 is speed limit
**/
function speedChecker(uint kph) public pure returns (string memory) {
uint MAX_LIMIT = 100;
if (kph > MAX_LIMIT) {
return 'Overspeeding';
}
return 'Not Overspeeding';
}
/**
Age-Based Access
Make a function that checks if a person can enter a restricted zone.
Notes:
13 - not allowed
13 - 17 - required with guardian
18 - allowed
*/
function ageRestriction(uint age) public pure returns (string memory) {
if (age >= 18) {
return 'Allowed';
} else if (age >= 13 && age <= 17) {
return 'Requires a guardian';
}
return 'Not allowed';
}
/**
Sum 1 to N
Make a function that will compute the sum of numbers from 1 to N.
Example: 5 → 1 + 2 + 3 + 4 + 5 = 15
*/
function sum1ToN(uint n) public pure returns (uint sum) {
for (uint i = 1; i <= n; i++) {
sum += i;
}
return sum;
}
/**
Even Numbers Printer
Make a function that adds up all even numbers up to N.
Example: Input: 10 → Output: 2 + 4 + 6 + 8 + 10 = 30
*/
function printEventNumbers(uint number) public pure returns (uint) {
uint sum = 0;
for (uint i = 1; i <= number; i++) {
if (i % 2 == 0) {
sum += i;
}
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment