Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarified hint text #1856

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Clarified hint text #1856

merged 1 commit into from
Mar 15, 2024

Conversation

JanB1
Copy link
Contributor

@JanB1 JanB1 commented Feb 12, 2024

The hint says that u32 would be more fitting for the prices. But this is only true for the original price and thus as an extension the parameters of the functions, not the type of the return value of sale_prince, as this could be negative for original_price values between 0 and 10 (specifically it will be negative for the input values of 1, 2, 4, 6 and 8).

Code for the exercise:

fn main() {
    let original_price = 51;
    println!("Your sale price is {}", sale_price(original_price));
}

fn sale_price(price: i32) -> i32 {
    if is_even(price) {
        price - 10
    } else {
        price - 3
    }
}

fn is_even(num: i32) -> bool {
    num % 2 == 0
}

PS. I know this might be pedantic and certainly will be very far down on the list of priorities, but I have stumbled over this hint multiple times, and the first time I encountered it I thought I was missing something and was quite stumped, just to figure out that the comment possible meant something else.

@shadows-withal shadows-withal merged commit 9bae712 into rust-lang:main Mar 15, 2024
5 checks passed
@shadows-withal
Copy link
Member

@all-contributors please add @JanB1 for content

Copy link
Contributor

@shadows-withal

I've put up a pull request to add @JanB1! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants