problem solving RRS feed

  • Question

  • Hi, I started to learn c# 4 days ago with an agency. And they give me a problem witch I cant solve. 

    The problem is like this:

    After it rains, there are red and white mushrooms. Red mushrooms are x times more then white once. Write an application that takes from keyboard the full numbers of mushrooms and the 'x', 1 after the other and return the number of the red mushrooms. 

    This is what I have so far. 

    using System;

    namespace problema_1
        class Program
            static void Main(string[] args)
                string inputData = Console.ReadLine();
                int amout = Convert.ToInt32(inputData);
                inputData = Console.ReadLine();

                int x = Convert.ToInt32(inputData);
                inputData = Console.ReadLine();

                int whiteMushrooms = 4;
                int redMushrooms = amout - (whiteMushrooms * x);


    But it does not work... 

    Sunday, September 29, 2019 10:16 AM

All replies

  • Check if agency accepts this:

       int whiteMushrooms = amount / 5;

       int redMushrooms = amount - whiteMushrooms;

    Also remove the last unneeded ReadLine.

    Sunday, September 29, 2019 12:33 PM
  • Hi Cody,

    Thank you for posting here.

    Based on your description, you want to get the red mushrooms according to the requirement you provided.

    I write a simple code example and I simplify your code.


     Console.WriteLine("Please enter the number of white mushrooms");
                int inputData = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Please enter the total number of mushrooms");
                int taotal= Convert.ToInt32(Console.ReadLine());
                int red = (taotal - inputData) / inputData;
                Console.WriteLine("you have "+red*inputData+"redmushrooms");


    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, September 30, 2019 2:47 AM
  • Greetings Cody.

    I won't write the code for you, because it's homework, but here is the formula.


    T = total number of mushrooms

    x = the multiple of red to white mushrooms

    R = number of red mushrooms (the number we are looking for).

    R = x * (T / (x + 1))

    For example, if T = 12 and x = 5 (we have twelve mushrooms and five times as many red as white), then;

    R = 5 * (12 / (5 + 1)) = 5 * 12 / 6 = 5 * 2 = 10

    So we have 10 red mushrooms and 2 white mushrooms giving 12 in total.

    Monday, September 30, 2019 3:11 AM