Вычитание из начального процента, но только когда пользователь вводит «нет» / false C# - PullRequest
0 голосов
/ 21 февраля 2020

в моем коде следующая проблема: у меня есть несколько операторов if, требующих ввода пользователя. И я хотел бы установить число (100), что если пользовательский ввод == нет, то х число вычитается из 100, но мне нужно это так сказать первый пользователь, чтобы сказать нет, (100-у) = а, а затем второй пользователь скажет нет, его значение вычтет ay скажем.

Счетчики используются для чего-то другого. Я вроде как новичок в C#, надеюсь, в этом есть смысл, вся помощь оценена.

namespace Ice_Cream
{
    class Program
    {
        static void Main(string[] args)
        {
            int counter = 0;
            int counter2 = 0;
            int counter3 = 0;
            int PercentageDisklikes = 100;

            string[] Foods = { "Icecream" , "Coffee" , "Sweetpotato" };
            string[] Dislike = { "5", "10", "3" };
            Console.WriteLine(Foods[0]);
            string Icecream = Console.ReadLine();
            Console.WriteLine("Do you like Ice cream? " );

            if (Icecream == "yes")
            {
                counter++;
                Console.WriteLine("Amount of ppl that like Ice cream: " + counter);




            }
            if (Icecream == "no")
            {
                counter2++;
                Console.WriteLine("Amount of ppl that don't like Ice cream " + counter2);
                Console.WriteLine("Study shows 10% of people agree with you");
                // Here i would like int PercentageDisklikes = 100 - 5 to then
                //Console.WriteLine("Ovr satisfaction (= 100 -5)
            }
            else if (Icecream == "maybe")
            {
                counter2++;
                counter3++;
                Console.WriteLine("Amount of ppl that don't like Ice cream : " + counter2);
                Console.WriteLine("Amount of ppl that maybe don't like Ice cream: " + counter3);
                // Here i would like int PercentageDisklikes = 100 - 5 to then
                //Console.WriteLine("Ovr satisfaction (= 100 -5)
            }

            Console.WriteLine(Foods[1]);
            string Coffee = Console.ReadLine();
            Console.WriteLine("Do you like Coffee? ");

            if (Coffee == "yes")
            {
                counter++;
                Console.WriteLine("Amount of ppl that like Coffee: " + counter);




            }
            if (Coffee == "no")
            {
                counter2++;
                Console.WriteLine("Amount of ppl that don't like Coffee " + counter2);
                Console.WriteLine("Study shows 10% of people agree with you");
                // Here i would like int PercentageDisklikes = 95 - 5 to then (95 from previous result)
                //Console.WriteLine("Ovr satisfaction (= 95 -5)
            }
            else if (Coffee== "maybe")
            {
                counter2++;
                counter3++;
                Console.WriteLine("Amount of ppl that don't like Coffee : " + counter2);
                Console.WriteLine("Amount of ppl that maybe don't like Coffee : " + counter3);
                // Here i would like int PercentageDisklikes = 95 - 5 to then
                //Console.WriteLine("Ovr satisfaction" + PercentageDislikes (= 95 -5)
            }


Ответы [ 2 ]

0 голосов
/ 21 февраля 2020

Я бы подошел к этому следующим образом. Посчитайте, сколько раз вы задаете вопрос. Подсчитайте ответы на каждый вопрос. Показать результаты.

        double numberAsked = 0;
        double yesIcecream = 0, noIcecream = 0, maybeIcecream = 0;
        while (true) // have a nice way to exit in your app
        {
            Console.WriteLine("Do you like Ice cream? ");
            string answer = Console.ReadLine();
            numberAsked++;
            if (answer == "yes")
            {
                yesIcecream++;
            }
            else if (answer == "no")
            {
                noIcecream++;
            }
            else if (answer == "maybe")
            {
                maybeIcecream++;
            }

            Console.WriteLine($"yes: { yesIcecream / numberAsked * 100}%");
            Console.WriteLine($"no: { noIcecream / numberAsked * 100 }%");
            Console.Write($"maybe: { maybeIcecream / numberAsked * 100 }%\n\n");
        }
0 голосов
/ 21 февраля 2020
 int counter = 0;
        int counter2 = 0;
        int counter3 = 0;
        string[] Foods = { "Icecream", "Coffee", "Sweetpotato" };
        string[] Dislike = { "5", "10", "3" };

        int PercentageDisklikes = 100;
        int subNumber = 5;

        Console.WriteLine(Foods[0]);
        string Icecream = Console.ReadLine();
        Console.WriteLine("Do you like Ice cream? ");

        if (Icecream == "yes")
        {
            counter++;
            Console.WriteLine("Amount of ppl that like Ice cream: " + counter);

        }
        else if (Icecream == "no")
        {
            counter2++;
            Console.WriteLine("Amount of ppl that don't like Ice cream " + counter2);
            Console.WriteLine("Study shows 10% of people agree with you");
            PercentageDisklikes = PercentageDisklikes - subNumber;
            Console.WriteLine($"Our satisfaction = {PercentageDisklikes}%");
        }
        else if (Icecream == "maybe")
        {
            counter2++;
            counter3++;
            Console.WriteLine("Amount of ppl that don't like Ice cream : " + counter2);
            Console.WriteLine("Amount of ppl that maybe don't like Ice cream: " + counter3);
            PercentageDisklikes = PercentageDisklikes - subNumber;
            Console.WriteLine($"Our satisfaction = {PercentageDisklikes}%");
        }

        //Here you must reset the counters, or you mix
        //Icecream and Coffe people

        counter = 0;
        counter2 = 0;
        counter3 = 0;
        Console.WriteLine(Foods[1]);
        string Coffee = Console.ReadLine();
        Console.WriteLine("Do you like Coffee? ");

        if (Coffee == "yes")
        {
            counter++;
            Console.WriteLine("Amount of ppl that like Coffee: " + counter);


        }
        if (Coffee == "no")
        {
            counter2++;
            Console.WriteLine("Amount of ppl that don't like Coffee " + counter2);
            Console.WriteLine("Study shows 10% of people agree with you");
            PercentageDisklikes = PercentageDisklikes - subNumber;
            Console.WriteLine($"Our satisfaction = {PercentageDisklikes}%");
        }
        else if (Coffee == "maybe")
        {
            counter2++;
            counter3++;
            Console.WriteLine("Amount of ppl that don't like Coffee : " + counter2);
            Console.WriteLine("Amount of ppl that maybe don't like Coffee : " + counter3);
            PercentageDisklikes = PercentageDisklikes - subNumber;
            Console.WriteLine($"Our satisfaction = {PercentageDisklikes}%");
        }

Я тоже не понимаю, что именно вы хотите. Если у вас есть еще вопросы, задавайте. Я тоже новичок в C# и могу вам сказать, что это не Python язык :-)

Прочтите это руководство, оно обойдется вам ровно в один день.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...