因此,我試圖讓一個酒店經理使用它自己的類來計算成本,具體取決於房間的高度,海景,多少間臥室和它根據這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 $開始? –