这是我的程序的代码:
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 环境运行它时,我在控制台中看到输出minutes
等于900
将1.5
小时数传递给我的程序。
如果我运行它www.ideone.com
,我会看到输出是90 minutes
相同的值1.5
。
我在哪里可以在我的代码中犯错误?为什么我的程序在不同地方运行时的行为会有所不同?