Finish cleanup of Assignment 6, complete of Rust, and most of 396's assignments.

This commit is contained in:
Charles Descamps 2024-11-25 01:05:10 -07:00
parent 5bdbe09523
commit 70d1cf9b35
8 changed files with 371 additions and 152 deletions

28
wordcounter.rs Normal file
View file

@ -0,0 +1,28 @@
use std::io;
fn main()
{
// input from the user to get the number of sentences they'd like to enter
println!("How many sentences would you like to input?");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
let mut num_sentences: u32 = input.trim().parse().expect("Please enter a number");
let mut total_words = 0;
// loop that would take input for each sentence
// calculates the number of words
while num_sentences > 0
{
println!("Please enter a sentence:");
input.clear();
io::stdin().read_line(&mut input).expect("Failed to read line");
let num_words = input.split_whitespace().count();
println!("The sentences has {} words", num_words);
total_words = total_words + num_words;
num_sentences = num_sentences - 1;
}
println!("Total number of words: {}", total_words);
}