這是我的程序代碼:程序行爲在不同的系統上是不同的。爲什麼?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YourGold
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to YourGold App! \n------------------------");
Console.WriteLine("Inesrt your gold: ");
int gold;
while (!int.TryParse(Console.ReadLine(), out gold))
{
Console.WriteLine("Please enter a valid number for gold.");
Console.WriteLine("Inesrt your gold: ");
}
Console.WriteLine("Inesrt your time(In Hours) played: ");
float hours;
while (!float.TryParse(Console.ReadLine(), out hours))
{
Console.WriteLine("Please enter a valid number for hours.");
Console.WriteLine("Inesrt your hours played: ");
}
float time = ((int)hours) * 60 + (hours % 1) * 100; ; // Here the calculation are wrong...
Console.WriteLine("Your total time playd is : " + time + " minutes");
float goldMin = gold/time;
Console.WriteLine("Your gold per minute is : " + goldMin);
Console.WriteLine("The application has ended, press any key to end this app. \nThank you for using it.\n but no thanks");
Console.ReadLine();
//Console.WriteLine(" \nApp self destruct!");
//Console.ReadLine();
}
}
}
當我嘗試使用我的本地的Visual Studio環境來運行它,我在控制檯看到,經過1.5
小時後當minutes
輸出等於900
我程序。
如果我運行這個www.ideone.com
,我看到輸出爲90 minutes
爲相同的值1.5
。
我在哪裏可以在我的代碼中犯錯誤? 爲什麼我的程序在不同的地方運行時有所不同?
您應該考慮爲您的問題提供良好的標題。 – Praveen