我需要你的指導來完成這個任務:
在可容納 500 名觀眾的 TEC Ballerup 體育場,每周日 10 點舉行足球比賽。打球的都是業余愛好者,看比賽是要花錢的。成人和兒童以及非俱樂部會員的觀眾均可進入(俱樂部會員可享受 10% 的折扣!)兒童票 30 丹麥克朗。成人票 65 丹麥克朗。兒童只能與成人一起進入. 先輸入要買多少成人票,再輸入要買多少兒童票。必須有一個好的指南,這樣程式的用戶就不會懷疑要輸入什么。
一種。計算并顯示價格后,程式必須詢問您是否是俱樂部協會組的成員。在這里你可以回答是或否。
灣。如果您是會員,您將獲得 10% 的折扣。列印折扣。
C。必須有兩個回圈(每個條目的門票數量一個),以便您最多可以訂購10張兒童票和10張成人票。
d。制作一份列印件,同時說明您總共購買了多少張門票。所以兒童票和成人票一起。
e. 一些外國個人觀眾愿意用歐元支付。修改程式,使它也能以歐元列印總價。期待現在的課程。是 757.34。確保四舍五入到整個歐元,因為我們不能用外幣返還。
F。添加日期,以便應用程式始終在螢屏右上角列印當前日期
到目前為止,我已經對此進行了編碼:
int maxNumber = 500;
int revenueSum = 0;
string adultBillet;
string childrenBillet;
int numberOrdered;
string numberOrderedString;
// How many adult tickets?
Console.WriteLine ("number of adult tickets");
Console.Write ("how many do you want?");
adultBillet = Console.ReadLine ();
// how many child tickets?
Console.WriteLine ("number of child tickets");
Console.Write ("how many do you want?");
childrenBillet = Console.ReadLine ();
String selection = "1";
while (choice! = "9")
{
Console.WriteLine ("How many adult tickets do you want ??");
numberOrdered = Convert.ToInt32 (Console.ReadLine ());
if (numberOrdered == 0)
{
Console.WriteLine ("You will need to purchase at least 1 ticket.");
}
else if (number Ordered> 10)
{
Console.WriteLine ("maximum number of adult tickets is 10.");
}
else if (numberOrdered> maxNumber)
{
Console.WriteLine ($ "Only {quantityOrder} left");
}
else
{
Console.WriteLine ($ "You have decided to purchase {number of Ordered} adult tickets");
}
Console.WriteLine ("are you a club member?");
Console.WriteLine ("please answer YES or NO");
String Club MemberReply = Console.ReadLine (). ToUpper ();
if (Club Member Answer == "YES")
{
Console.Write (numberOrdered * 65 * 0.9);
}
else if (Club MemberReply == "NO")
{
Console.Write(AmountofTickets * 65);
}
else
{
Console.WriteLine("Invalid answer");
我被困在現在該怎么辦?到處都是,但是我想我需要一個回圈來存放成人票和兒童票,以及總共有多少張票,歐元和丹麥克朗,最后是日期
uj5u.com熱心網友回復:
我根據您的要求為您做了一個demo,僅供您參考。
您可以使用以下代碼首先設定控制臺的大小。
Console.SetWindowSize(100, 50);
Console.SetBufferSize(100, 50);
使用它來輸出日期
Console.CursorLeft = Console.BufferWidth - 10;
Console.Write("{0}\n", DateTime.Now.ToString("yyyy-MM-dd"));
用于int.TryParse防止用戶輸入錯誤資訊。
主要有兩個回圈,大回圈購買成人票和小回圈購買兒童票。
判斷條件更簡單。輸入指定字符視為是,否則視為否。
下面是我的代碼:
using System;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
double adultPrice = 65, kidPrice = 30, totalPrices = 0;
int tmpTickets = 0, adultTickets = 0, kidsTickets = 0, totalTickets = 0, EurPrices = 0;
bool adultSuccess = false, kidSuccess = false;
Console.SetWindowSize(100, 50);
Console.SetBufferSize(100, 50);
Console.CursorLeft = Console.BufferWidth - 10;
Console.Write("{0}\n", DateTime.Now.ToString("yyyy-MM-dd"));
Console.WriteLine("Welcome Ticket Mall!\n"
"AdultPrice 65 DKK,childrenPrice 30 DKK.\n"
"You can order a maximum of 10 children's tickets and 10 adult tickets.\n"
"A child enters with an adult, so the child ticket cannot be larger than the adult ticket.");
while (!adultSuccess)
{
Console.WriteLine("Please enter the number of adult tickets.");
if (adultSuccess = int.TryParse(Console.ReadLine(), out tmpTickets))
{
if (tmpTickets < 0 || tmpTickets > 10)
{
Console.WriteLine("input error!please enter again!");
adultSuccess = false;
}
else if (tmpTickets == 0)
{
Console.WriteLine("Thanks for using, bye.");
}
else
{
adultTickets = tmpTickets;
Console.WriteLine("Do you need to buy a child ticket?\n"
"Enter 'Y' or 'y' to go to the next step.");
string tmp = Console.ReadLine();
if (tmp != "Y" && tmp != "y")
{
break;
}
else
{
while (!kidSuccess)
{
Console.WriteLine("Please enter the number of kids tickets.");
if (kidSuccess = int.TryParse(Console.ReadLine(), out tmpTickets))
{
if (tmpTickets < 0 || tmpTickets > adultTickets)
{
Console.WriteLine("input error!please enter again!");
kidSuccess = false;
}
else
{
kidsTickets = tmpTickets;
}
}
}
}
}
}
}
Console.Clear();
Console.CursorLeft = Console.BufferWidth - 10;
Console.Write("{0}\n", DateTime.Now.ToString("yyyy-MM-dd"));
totalPrices = adultTickets * adultPrice kidsTickets * kidPrice;
totalTickets = adultTickets kidsTickets;
Console.WriteLine($"You have decided to purchase {adultTickets} adult tickets {kidsTickets} kid tickets\n"
$"Total {totalTickets} tickets , {totalPrices} DKK ");
Console.WriteLine("are you a club member?\n"
"Enter 'Y' or 'y' as a member.");
var tmp2 = Console.ReadLine();
if (tmp2 != "Y" && tmp2 != "y")
{
//1 Danish Krone is equal to 0.13 EUR now
EurPrices = Convert.ToInt32(totalPrices * 0.13);
Console.WriteLine($"You need to pay {totalPrices} DKK or {EurPrices} EUR! ");
}
else
{
totalPrices = totalPrices * 0.9;
EurPrices = Convert.ToInt32(totalPrices * 0.13);
Console.WriteLine($"As a member! You need to pay {totalPrices} DKK or {EurPrices} EUR !");
}
//Pause
Console.ReadLine();
}
}
}
這是我的演示的螢屏截圖:


轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/466797.html
