Why isn’t my Rust code updating the teacher’s name properly?

0
5
Asked By CuriousCoder123 On

I'm working on a Rust program to manage a teacher's information, but I'm puzzled why my code updates the subject but not the teacher's name. Here's the relevant code: I'm creating a struct for the teacher with a name, ID, and subject. After adding a teacher with the name 'Hari Bahadur' and subject 'History', I try to update the subject to 'English' and the name to 'Hari only'. Although the output shows the updated subject correctly, the teacher's name doesn't seem to change as expected. Can someone help me understand what's going wrong?

1 Answer

Answered By CodeNinja42 On

When I run your code, I see:

The name of the teacher is Hari Bahadur
Now Hari only teaches English

The first line prints out the original name before you update it, while the second line shows the updated name after you make the changes. So it seems like your updates are working correctly; maybe you just misinterpreted the output?

PuzzledLearner -

So there is some problem with my cargo run it seems.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.