Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement add, difference, multiplication and division functions #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 29 additions & 13 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
fn main() {
short_str();
let result = check_num(30);
println!("check_sum fn result here: {result}");
let sum: u16 = add_num(10, 5);
println!("the sum of 2 numbers is: {sum}");
println!("Check_sum function result here: {}", result); // Fixed the string interpolation syntax
let sum: u16 = add_num(20, 4);
println!("The sum is: {}", sum); // Fixed the string interpolation syntax
let diff: u16 = sub_num(12, 3);
println!("The difference is: {}", diff); // Fixed variable name mismatch in string interpolation
let mul_val: u16 = mul_num(4, 5);
println!("The product is {}", mul_val);
let div_val: u16 = div_num(12, 2);
println!("The result is {}", div_val);
}

// short string data type
// Short string data type
fn short_str() {
println!("GM Cairo!");
println!("Good morning, Cairo!");
}

// bool data type
// Boolean data type
fn check_num(n1: u8) -> bool {
if n1 > 20 {
return true;
}
return false;
n1 > 20 // Simplified boolean return
}

// function to perform basic addition arithmetic operation
// Function to perform basic addition arithmetic operation
fn add_num(n1: u16, n2: u16) -> u16 {
let result: u16 = n1 + n2;
return result;
n1 + n2 // Simplified return
}

// Function to perform basic subtraction arithmetic operation
fn sub_num(n1: u16, n2: u16) -> u16 {
n1 - n2 // Simplified return
}

// Function to perform basic multiplication arithmetic operation
fn mul_num(n1: u16, n2: u16) -> u16 {
n1 * n2 // Simplified return
}

// Function to perform basic division arithmetic operation
fn div_num(n1: u16, n2: u16) -> u16 {
n1 / n2 // Corrected syntax and simplified return
}