小编rob*_*yek的帖子

为什么Rust程序不从if语句返回值?

我正在制作一个简单的控制台程序,可以在Celsius和Fahrenheit之间进行转换.该程序多次获取用户输入,一次用于转换类型,一次用于转换值.当我运行程序时,它编译并运行没有错误,但是,它实际上不返回任何值.

这是程序:

use std::io;

// C to F: F = C*(9/5) + 32
// F to C: C = (F-32)*(5/9)

/**********Converts between Fahrenheit and Celsius*********/

fn main() -> () {
    println!("Do you want to convert to Celsius or Fahrenheit? Input C or F");
    let mut convert_type = String::new();

    io::stdin()
        .read_line(&mut convert_type)
        .expect("Failed to conversion type.");

    let t = String::from(convert_type);

    println!("You want to convert to: {}", t);
    println!("What temperature would you like to convert?");
    let mut temp = String::new();

    io::stdin()
        .read_line(&mut …
Run Code Online (Sandbox Code Playgroud)

rust

3
推荐指数
1
解决办法
117
查看次数

标签 统计

rust ×1