Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit for find-sum-of-digits-of-a-number.jl #4770

Closed
Closed
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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
fn main(){
let input = "hello world!";
let mut ans = String::with_capacity(input.len());
let mut next = true;
for i in input.chars(){
if next{
ans.push(i.to_ascii_uppercase());
next = false;
} else {
ans.push(i.to_ascii_lowercase());
}
use std::io;

fn main() {
println!("Enter a string:");
let mut input = String::new();

// Reading input from user and handling possible errors
if let Err(e) = io::stdin().read_line(&mut input) {
eprintln!("Failed to read line: {}", e);
return;
}

// Processing the input string
match to_consonantcase(&input.trim()) {
Ok(consonantcase_string) => println!("Consonantcase: {}", consonantcase_string),
Err(e) => eprintln!("Error processing string: {}", e),
}
println!("{}", ans);
}
}

fn to_consonantcase(s: &str) -> Result<String, &'static str> {
// Check for empty string
if s.is_empty() {
return Err("Input string is empty");
}

let transformed = s.chars().map(|c| {
match c {
'a' | 'e' | 'i' | 'o' | 'u' |
'A' | 'E' | 'I' | 'O' | 'U' => c.to_lowercase().to_string(),
_ => c.to_uppercase().to_string(),
}
}).collect();

Ok(transformed)
}