Last active
October 19, 2022 11:08
-
-
Save nodomw/0eb9746c822ad4789f9b5f57411bb375 to your computer and use it in GitHub Desktop.
informatikai alapvizsga feladat gyakorlás
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
struct Kutya { | |
name: String, | |
age: i32, | |
breed: String, | |
owner: String, | |
} | |
fn main() { | |
let mut count: i32 = 0; | |
let mut name = String::new(); | |
let mut age = String::new(); | |
let mut breed = String::new(); | |
let mut owner = String::new(); | |
let mut dogs: Vec<Kutya> = Vec::new(); | |
let mut tocount = String::new(); | |
println!("Hány kutyát szeretnél hozzáadni?"); | |
io::stdin() | |
.read_line(&mut tocount) | |
.expect("Failed to read line"); | |
loop { | |
println!("Mi a neve a kutyának?"); | |
io::stdin() | |
.read_line(&mut name) | |
.expect("Failed to read line"); | |
println!("Hány éves {}?", name.trim()); | |
io::stdin() | |
.read_line(&mut age) | |
.expect("Failed to read line"); | |
io::stdin() | |
.read_line(&mut breed) | |
.expect("Failed to read line"); | |
println!("Ki a gazdája {}-nak/nek?", name.trim()); | |
io::stdin() | |
.read_line(&mut owner) | |
.expect("Failed to read line"); | |
let dog = Kutya { | |
name: name.trim().to_string(), | |
age: age.trim().parse().unwrap(), | |
breed: breed.trim().to_string(), | |
owner: owner.trim().to_string(), | |
}; | |
dogs.push(dog); | |
name.clear(); | |
age.clear(); | |
breed.clear(); | |
owner.clear(); | |
count += 1; | |
if count == tocount.trim().parse().unwrap() { | |
break; | |
} | |
} | |
for dog in dogs { | |
println!("---------------------------" ); | |
println!("Név: {}", dog.name); | |
println!("Kor: {}", dog.age); | |
println!("Fajta: {}", dog.breed); | |
println!("Gazda: {}\n", dog.owner); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment