披萨店的算法,哪个更好? [英] Algorithm for a pizza shop, which one is better?

查看:96
本文介绍了披萨店的算法,哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿那里,我想写一个披萨店的算法(c#)



i写道,我把它展示给我的朋友,我的朋友说:你的算法是错的。他写了另一个算法。



现在我想知道哪个算法更好?



告诉我哪一个更好更正确? (有理由)



我的尝试:



Hey there, i want to write an algorithm for a pizza shop (c#)

i wrote and i showed it to my friend, my friend said: your algorithm is wrong. and he wrote another algorithm.

and right now i want to know which one of our algorithm is better?

tell me which one is better and correct? (with reason)

What I have tried:

Console.WriteLine("Welcome! We have 3 different sizes, which do you want?: 1.Small - 2.Meduim - 3.Large");
            Console.Write("Enter Your Selection: ");
            int userSelection = int.Parse(Console.ReadLine());
            int price = 0;
            //there is my code:

            switch (userSelection)
            {
                case 1:
                    price += 5;
                    Console.WriteLine("You are selected Small size, We'll send you :)");
                    Console.WriteLine("Price: " + price + "$");
                    break;

                case 2:
                    price += 10;
                    Console.WriteLine("You are selected Medium size, We'll Send you :)");
                    Console.WriteLine("Price: " + price + "$");
                    break;

                case 3:
                    price += 15;
                    Console.WriteLine("You are selected Large size, We'll Send you :)");
                    Console.WriteLine("Price: " + price + "$");
                    break;

                default:
                    Console.WriteLine("Please enter the number of size that you want! (1 - 3)");
                    break;

//this is my friend's code:

switch (userSelection)
            {
                case 1:
                    price += 5;
                    break;

                case 2:
                    price += 5;
                    goto case 1;

                case 3:
                    price += 5;
                    goto case 1;
                default:
                    Console.WriteLine("please enter number of your selection");
                    break;
            }

            if (price != 0)
            {
                Console.WriteLine("Your selection is " + userSelection + ", we'll send you");
                Console.WriteLine("Price: " + price);
            }
            }


推荐答案

);
break;

case 2:
price + = 10;
Console.WriteLine(你选择中等大小,我们会发送给你:));
Console.WriteLine(价格:+价格+
"); break; case 2: price += 10; Console.WriteLine("You are selected Medium size, We'll Send you :)"); Console.WriteLine("Price: " + price + "


);
休息;

案例3:
价格+ = 15;
Console.WriteLine(你被选中大尺寸,我们会发给你:));
Console.WriteLine(Price: +价格+
"); break; case 3: price += 15; Console.WriteLine("You are selected Large size, We'll Send you :)"); Console.WriteLine("Price: " + price + "


);
休息;

默认:
Console.WriteLine(请输入大小的数量你想要的!(1 - 3));
休息;

//这是我朋友的代码:

switch(userSelecti on)
{
案例1:
价格+ = 5;
休息;

案例2:
价格+ = 5;
转到案例1;

案例3:
价格+ = 5;
转到案例1;
默认值:
Console.WriteLine(请输入您选择的号码);
休息;
}

如果(价格!= 0)
{
Console.WriteLine(您的选择是+ userSelection +,我们会发给您) ;
Console.WriteLine(价格:+价格);
}
}
"); break; default: Console.WriteLine("Please enter the number of size that you want! (1 - 3)"); break; //this is my friend's code: switch (userSelection) { case 1: price += 5; break; case 2: price += 5; goto case 1; case 3: price += 5; goto case 1; default: Console.WriteLine("please enter number of your selection"); break; } if (price != 0) { Console.WriteLine("Your selection is " + userSelection + ", we'll send you"); Console.WriteLine("Price: " + price); } }



这篇关于披萨店的算法,哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆