Menu
Coddy logo textTech

Recap - Grade Summarizer

Part of the Logic & Flow section of Coddy's Rust journey — lesson 66 of 66.

challenge icon

Challenge

Easy

You will receive multiple inputs representing student grades. The first input is a number indicating how many grades will follow. Then you will receive that many grade values (one per line). Process these grades and provide a comprehensive summary.

Requirements:

  • Read the first input (number of grades), trim whitespace, and parse it to i32
  • Create an empty vector to store the grades
  • Use a loop to read each grade, trim whitespace, parse it to i32, and add it to the vector
  • Calculate the average grade (sum of all grades divided by the count)
  • Find the highest grade in the vector
  • Find the lowest grade in the vector
  • Count how many grades are passing (70 or above)
  • Count how many grades are failing (below 70)
  • Print the results in the exact format shown below

Output Format:

  • Line 1: Average: X (where X is the average as an integer)
  • Line 2: Highest: X (where X is the highest grade)
  • Line 3: Lowest: X (where X is the lowest grade)
  • Line 4: Passing: X (where X is the count of passing grades)
  • Line 5: Failing: X (where X is the count of failing grades)

Input:

  • First line: Number of grades (e.g., 5)
  • Following lines: Individual grade values (e.g., 85, 92, 67, 78, 95)

Output:

  • Five lines showing the average, highest, lowest, passing count, and failing count

Try it yourself

use std::io;

fn main() {
    // Read the number of grades
    let mut count_input = String::new();
    io::stdin().read_line(&mut count_input).expect("Failed to read line");
    let count: i32 = count_input.trim().parse().expect("Invalid number");
    
    // Create a vector to store grades
    let mut grades: Vec<i32> = Vec::new();
    
    // Read each grade
    for _ in 0..count {
        let mut grade_input = String::new();
        io::stdin().read_line(&mut grade_input).expect("Failed to read line");
        let grade: i32 = grade_input.trim().parse().expect("Invalid number");
        grades.push(grade);
    }
    
    // TODO: Write your code below
    // Calculate average, find highest, find lowest, count passing and failing grades
    
    
    
    // Output the results in the required format
    // println!("Average: {}", average);
    // println!("Highest: {}", highest);
    // println!("Lowest: {}", lowest);
    // println!("Passing: {}", passing_count);
    // println!("Failing: {}", failing_count);
}

All lessons in Logic & Flow