c# - C#:打印多个输入结果
问题描述
我是 C# 编码的新手,所以我的代码非常简单明了,但是在显示用户输入结果时遇到了问题。我的代码用于电影院,用户可以在其中选择他们想看的电影、时间和他们想要的门票数量。其他数据包括电影的评分和正在播放的屏幕!我有多个循环正在进行,在用户做出每个决定后,我都试图将它们存储在一个“顺序”结构中。最后我可以做出一个决定来展示
但我无法显示其他决定。
这是我的代码:
do
{
do
{
Console.WriteLine("Welcome to PJs Cinema!"); //welcome line
do
{
Console.WriteLine("Please enter in the corresponding number to the movie you wish to see.");
for (i = 1; i < maxMovie; i++)
{
Console.WriteLine("{0}. {1}", i, movieList[i].movie); //displays movies
}
do
{
try
{
movieSelString = Console.ReadLine(); //customer chooses
movieSel = int.Parse(movieSelString);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Please choose a number between 1 and {0}.", maxMovie); //guidelines for customer
}
if (movieSel < 1 || movieSel > maxMovie)
{
Console.WriteLine("Invalid Entry: {0}. Please select a number between 1 and {1}.", movieSel, maxMovie); //invalid response
}
}
while (movieSel < 1 || movieSel > maxMovie);
Console.WriteLine("You have selected the movie {0} (rated {1}) at a price of ${2} per ticket. Is that correct, Y or N?", movieList[movieSel].movie, movieList[movieSel].rating, movieList[movieSel].price); //confirm decision for movie title and price
answer = Console.ReadLine();
if (answer == "Y") //boolean to see if needs to repeat
{
validData = false;
}
}
while (validData);
validData = false;
orderList[1].movieDec = movieList[movieSel].movie; //storing the movie title
orderList[1].rating = movieList[movieSel].rating; //storing the movie rating
orderList[1].ppTicket = movieList[movieSel].price; //storing the price
//orderList[2].movieDec = movieList[movieSel].movie;
//orderList[2].rating = movieList[movieSel].rating;
//orderList[2].ppTicket = movieList[movieSel].price;
//orderList[3].movieDec = movieList[movieSel].movie;
//orderList[3].rating = movieList[movieSel].rating;
//orderList[3].ppTicket = movieList[movieSel].price;
//orderList[4].movieDec = movieList[movieSel].movie;
//orderList[4].rating = movieList[movieSel].rating;
//orderList[4].ppTicket = movieList[movieSel].price;
//orderList[5].movieDec = movieList[movieSel].movie;
//orderList[5].rating = movieList[movieSel].rating;
//orderList[5].ppTicket = movieList[movieSel].price;
do
{
Console.WriteLine("{0} is playing on screen number {1} at the following times:", movieList[movieSel].movie, movieList[movieSel].screening); //movie time menu
i = movieSel;
Console.WriteLine("1. {0}", movieList[i].time1);
Console.WriteLine("2. {0}", movieList[i].time2);
Console.WriteLine("3. {0}", movieList[i].time3);
Console.WriteLine("Which time would you like to select (1-{0})?", maxTime); //customer selection prompt
do
{
try
{
timeSelString = Console.ReadLine(); //customer selection
timeSel = int.Parse(timeSelString);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Please choose a number between 1 and {0}.", maxTime); //selection parameters
}
if (timeSel < 1 || timeSel > maxTime)
{
Console.WriteLine("Invalid Entry: {0}. Please select a number between 1 and {1}.", timeSel, maxTime); //invalid response
}
}
while (timeSel < 1 || timeSel > maxTime);
switch (timeSel)
{
case 1:
officialTime = movieList[i].time1;
break;
case 2:
officialTime = movieList[i].time2;
break;
case 3:
officialTime = movieList[i].time3;
break;
default:
break;
}
Console.WriteLine("You have selected the time {0}. Is that correct, Y or N?", officialTime); //confirming time
answer = Console.ReadLine();
if (answer == "Y") //boolean to see if needs to repeat
{
validData = false;
}
if (answer == "N") //boolean to see if needs to repeat
{
validData = true;
}
}
while (validData);
validData = false;
orderList[1].screenDec = movieList[movieSel].screening; //storing screen
orderList[1].timeDec = officialTime; //storing time
//orderList[2].screenDec = movieList[movieSel].screening;
//orderList[2].timeDec = officialTime;
//orderList[3].screenDec = movieList[movieSel].screening;
//orderList[3].timeDec = officialTime;
//orderList[4].screenDec = movieList[movieSel].screening;
//orderList[4].timeDec = officialTime;
//orderList[5].screenDec = movieList[movieSel].screening;
//orderList[5].timeDec = officialTime;
do
{
Console.WriteLine("How many tickets would you like to purchase (1-{0})?", maxTickets); //number of tickets question
do
{
try
{
ticketSelString = Console.ReadLine(); //customer decision
ticketSel = int.Parse(ticketSelString);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Please choose a number between 1 and 30."); //parameters for decision
}
if (ticketSel < 1 || ticketSel > maxTickets)
{
Console.WriteLine("Invalid Entry: {0}. Please select a number between 1 and {1}", ticketSel, maxTickets); //invalid entry
}
}
while (ticketSel < 1 || ticketSel > maxTickets);
subtotal = ticketSel * movieList[movieSel].price;
Console.WriteLine("{0} tickets at ${1} each comes to a subtotal of ${2}. Is that correct, Y or N?", ticketSel, movieList[movieSel].price, subtotal); //confirmation of entry
answer = Console.ReadLine();
if (answer == "Y") //boolean to see if needs to repeat
{
validData = false;
}
if (answer == "N") //boolean to see if needs to repeat
{
validData = true;
}
}
while (validData);
orderList[1].numTickets = ticketSel; //storing ticket number selection
//orderList[2].numTickets = ticketSel;
//orderList[3].numTickets = ticketSel;
//orderList[4].numTickets = ticketSel;
//orderList[5].numTickets = ticketSel;
Console.WriteLine("You have chosen to buy {0} tickets at ${1} each to see {2}, rated {3} at {4}.", ticketSel, orderList[movieCount].ppTicket, orderList[movieCount].movieDec, orderList[movieCount].rating, orderList[movieCount].timeDec); //conplete confirmation
Console.WriteLine("Would you like to see another movie, Y or N?"); //nother movie?
answer = Console.ReadLine();
if (answer == "Y") //boolean to see if needs to repeat
{
validData = true;
}
else
{
movieCount++; //add to the movie count
}
}
while (validData);
//grandTotal = subtotal[movieCount] = subtotal[movieCount];
//Console.Clear(); //clear the screen
Console.WriteLine("Here is your receipt:"); //title of receipt
Console.WriteLine("{0,-17}{1,-10}{2,-10}{3,-10}{4,-9}{5,-10}{6,-15}", mmovie, rrating, pprice, sscreen, ttime, ttickets, ssubtotal); //columns
for (movieCount = 1; movieCount < maxCount; movieCount++)
{
Console.WriteLine("{0,-17}{1,-10}${2,-10}{3,-9}{4,-9}{5,-10}${6,-15}", orderList[movieCount].movieDec, orderList[movieCount].rating, orderList[movieCount].ppTicket, orderList[movieCount].screenDec, orderList[movieCount].timeDec, orderList[movieCount].numTickets, subtotal); //customers decisions
}
//Console.WriteLine("Grandtotal = {0}", grandTotal); //grandtotal display
Console.WriteLine("Thank you so much for joining us at PJs Cinema! Enjoy!"); //thank you!!
}
while (validData);
我不确定如何单独存储决定。有什么建议吗?
解决方案
推荐阅读
- javascript - Promise 和 create-react-app 的问题
- python - Windows PowerShell 中的烧瓶问题
- javascript - 将 React 组件作为对象值返回并将道具绑定到它
- reactjs - 如何从 Redux-Saga 中选择状态
- flutter - 如何在颤动中使用此图像中的容器内的半圆形?
- dart - 如何访问 Dart 内置方法的源代码?
- javascript - 获取当前 CSS 网格布局中的角项目,在悬停时展开
- javascript - 如何在 React 中添加新类而不重置以前的类
- mysql - 如果 mysql 中的前两行相同,则返回 null
- powerbuilder - 将波浪号添加到数据窗口 setFilter 字符串