在C#中,当我输入royaltyRate时,我收到错误格式的错误消息。例:.25 [英] In C#, I get error message incorrect format when I enter the royaltyRate. Ex: .25
问题描述
嗨!
我是编程新手。
我为一个课程项目编写了这个简短的程序。用户输入书籍或杂志,销售数量,每单位价格和版税率。该计划返回总金额加上应付客户的特许权使用费总额。当我测试程序时,我无法进入royaltyRate。当我收到版税率错误格式的错误。我尝试了几种不同的输入速率的方法,但我仍然得到同样的错误。有人可以给我一个如何解决这个错误的提示吗?
感谢您的帮助!
Hi!
I am new at programming.
I wrote this short program for a class project. The user enters book or magazine, quantity sold, price per unit, and royalty rate. The program returns total amount plus total royalties due client. I can't get past entering the "royaltyRate" when I am testing the program. When I get an error for the "royalty rate" incorrect format. I have tried several different ways of entering the rate, but I still get the same error. Can someone give me a tip on how to solve this error?
Thanks for you assistance!
static void Main(string[] args)
{
Console.WriteLine("Welcome to the Royalty Calculation Application!");
Console.WriteLine("Please enter Clients Name: ");
string clientName = Convert.ToString(Console.ReadLine());
Console.WriteLine("Please enter Item Name: ");
string itemName = Convert.ToString(Console.ReadLine());
Console.WriteLine("Please enter quantity sold: ");
int quantity = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter unit price per item: {C:0} ");
decimal price = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("Please enter Royalty Rate: ");
decimal royaltyRate = Convert.ToDecimal(Console.ReadLine());
decimal totalSold = quantity * price;
Console.WriteLine("Total Amount Sold: {C:0} ", totalSold);
decimal royaltyToBePaid = totalSold * royaltyRate;
Console.WriteLine("Total Royalty due Client: {C:0} ", royaltyToBePaid);
}
推荐答案
字符串中的{0}
是应该表示传递给WriteLine的参数号。
以下
The{0}
in the string is supposed to represent the parameter number that is being passed to the WriteLine.
The following
Console.WriteLine("Total Amount Sold: {0} ", totalSold);
Console.WriteLine("Total Amount Sold: {0} ", totalSold.ToString("C2"));
产生
produces
Total Amount Sold: 300
Total Amount Sold: £300.00
static void Main(string[] args)
{
Console.WriteLine("Welcome to the Royalty Calculation Application!");
Console.WriteLine("Please enter Clients Name: ");
string clientName = Convert.ToString(Console.ReadLine());
Console.WriteLine("Please enter Item Name: ");
string itemName = Convert.ToString(Console.ReadLine());
Console.WriteLine("Please enter quantity sold: ");
int quantity = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter unit price per item: ");
decimal price = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("Please enter Royalty Rate: ");
decimal royaltyRate = Convert.ToDecimal(Console.ReadLine());
decimal totalSold = quantity * price;
Console.WriteLine("Total Amount Sold: {0} ", totalSold.ToString("C2"));
decimal royaltyToBePaid = totalSold * royaltyRate;
Console.WriteLine("Total Royalty due Client: {0} ", royaltyToBePaid.ToString("C2"));
}
这篇关于在C#中,当我输入royaltyRate时,我收到错误格式的错误消息。例:.25的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!