First assignment of stellar coding class

⚓ Rust    📅 2025-09-04    👤 surdeus    👁️ 2      

surdeus

fn main(){
//task1 integers
let Peanut:i32=8;
println!("i am bringing {} Peanut",Peanut);

//task2 floating    
let Milk:f64=2.6;    
println!("i have {} Milk",Milk);    
  
//task3 booleans
let kite:bool=false;
if kite{
   println!("I can go high");
}else{
   println!("try again");
}

//task4 characters
let initial:char= 'K';
 println!("my pen has a:{}",initial);
 
 
 //task5 Tuples
 let lunchbox=("protail",1,2,3,4,5);
  println!("I eat {} with {}fruit and {} banana {} cups of milk {} Salad",lunchbox.1,lunchbox.2,lunchbox.3,lunchbox.4,lunchbox.5);
 
 //task6 Arraal
 let colleagues=["Zigama","D'Assisse","Belyse"];
 println!("{}my colleagues!",colleagues[1]);
 
 
 //task7 Mutability
 let mut apple = 6;
 println!("apple before:{}",apple);
 apple=apple+2;
 println!("apple after {}",apple);
 
 
 //task8 Shadowing
 let water=2;
 println!("water:{}",water);
 let water=water+2;
 println!("more water {}",water);
     
  
    
}

(Playground)

Output:

i am bringing 8 Peanut
i have 2.6 Milk
try again
my pen has a:K
I eat 1 with 2fruit and 3 banana 4 cups of milk 5 Salad
D'Assissemy colleagues!
apple before:6
apple after 8
water:2
more water 4

Errors:

   Compiling playground v0.0.1 (/playground)
warning: variable `Peanut` should have a snake case name
 --> src/main.rs:3:5
  |
3 | let Peanut:i32=8;
  |     ^^^^^^ help: convert the identifier to snake case: `peanut`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: variable `Milk` should have a snake case name
 --> src/main.rs:7:5
  |
7 | let Milk:f64=2.6;    
  |     ^^^^ help: convert the identifier to snake case: `milk`

warning: `playground` (bin "playground") generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s
     Running `target/debug/playground`

2 posts - 2 participants

Read full topic

🏷️ Rust_feed