Unterminated double quote string

I am a beginner Rustacean. I am getting aforementioned error. But unable to find the error in code. The error screen shot:

The code is:

use std::io;
fn main() {
    loop {
        println!("1: Convert temperature from Fahrenheit to Celsius.");
        println!("2: Convert temperature from Celsius to Fahrenheit.");
        println!("3: Quit"); 
        println!("Enter your choice (1, 2, 3);
        let mut choice = String::new();
            .read_line(&mut choice)
            .expect("Failed to read line");
        let choice: u32 = choice.trim().parse().expect("Invalid Input");
        if choice == 1 {
            println!("Enter temperature in Fahrenheit:");
            let mut fahrenheit = String::new();
                .read_line(&mut fahrenheit)
                .expect("Failed to read line");
            let fahrenheit: f32 = fahrenheit.trim().parse().expect("Invalid Input");
            let result: f32 = (fahrenheit - 32 as f32) / 1.8;
            println!("Temperature in Celsius {}",result );
        if choice == 2 {
            println!("Enter temperature in Celsius:");
            let mut celsius = String::new();
                .read_line(&mut celsius)
                .expect("Failed to read line");
            let celsius: f32 = celsius.trim().parse().expect("Invalid Input");
            let result: f32 = (celsius * 1.8)+(32 as f32);
            println!("Temperature in Fahrenheit {}",result );

        if choice == 3{

I can’t see any error in the code. Please help me out. Thanks in advance

println!("Enter your choice (1, 2, 3);

You’re missing the closing quote here.

I can highly recommend using an editor with syntax highlighting such as VS Code, this can make it very obvious where the error is for syntax errors like this.


I am focused on line 31 as directed by the compiler. The compiler should have pointed to correct line no. The correct line no. is 7. Is this a bug in compiler.
Thank you for the resolution

The code on line 7 appears to be valid code to the compiler, because it doesn’t know that “let mut choice…” on line 8 was meant to be a new line of code. It looks like a valid multi-line string literal, for example:

let poem = "Roses are red,
            violets are blue.";

By the way, even simply dropping your code into playground would help you here, since it also has syntax highlighting, and the problem would be easily seen.

1 Like

Yes, it could have helped. Compiler could have also helped if it points to the starting point. But it pointed towards the end.

And how would you check if the starting point is an error? Although I think it could throw an error on the .expect("Failed to read line"); line, since Failed is not a known token at this place. But I can’t think of any way to detect that the problem is several lines before.

You may be right. I don’t have knowledge of compilers. Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.