因此,我试图让一个酒店经理使用它自己的类来计算成本,具体取决于房间的高度,海景,多少间卧室和它根据这3个变量吐出成本。c#编写一个管理酒店房间的代码/计算
我被卡住了,因为当我尝试运行这个没有任何计算,只是为了看看它是否工作到目前为止它不会返回/重申我已经输入。有一个错误说“FormatException发生”
我对c#很新,所以我很感激任何可以给予的帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace myHotel
{
class Program
{
static void Main(string[] args)
{
Apartment myApartment = new Apartment();
Console.WriteLine("Hotel Building Number:");
myApartment.BuildingNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter your Hotel room number:");
myApartment.ApartmentNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter the number of Bedrooms you have:");
myApartment.Type = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter 1 for Ocean View and 2 for no Ocean view:");
myApartment.View = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter your name");
myApartment.Name = Console.ReadLine();
Console.WriteLine("{0} {1} {2} {3} {4} {5}",
myApartment.BuildingNumber,
myApartment.ApartmentNumber,
myApartment.Type,
myApartment.View,
myApartment.View);
Console.ReadLine();
}
}
class Apartment
{
public int BuildingNumber { get; set; }
public int ApartmentNumber { get; set; }
public int Type { get; set; }
public int View { get; set; }
public string Name { get; set; }
}
}
谢谢,我接受了你的建议,它的工作很棒。 现在,如果我想添加变量,取决于房间是否有1卧室800 $,2卧室850,3bedrooms 900 $。使用这些数字作为基准价格,然后增加50美元的海景,然后25美元,如果你的公寓数量高于300. 我会使用另一个字符串致力于货币从0 $开始? –