0

I'm trying to solve a Kata where I'm asked to "count sheep". A function count_sheep is called with a positive integer as parameter. I'm supposed to return a string with a murmur: "1 sheep...2 sheep...3 sheep..."

This is what I have so far:

fn count_sheep(n: u32) -> String {
    let mut Sheep_vec = String::new();
    let mut i = 1;
    while i <= n {
        sheep_string = ("{} sheep..", i);
        Sheep_vec.push(sheep_string);
        i = i + 1;
    }
    Sheep_vec
}

I wanted to return the string analog to the println! macro, but that fails, because .push() doesn't support multiple argumentss.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • [The duplicates applied to your situation](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2ff0254bfd94f2d70c2e71fda131b520), or [if you actually wanted a `Vec`](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b06fe8456a8bb4101b4bc796a3b0c099) – Shepmaster Mar 31 '21 at 14:41
  • Thankl you very much @shepmaster – Sergej Pronchenko Mar 31 '21 at 15:14

0 Answers0