C#的简单代码,请帮助我:( [英] Simple codes for C# please help me :(
问题描述
using System;
namespace PrintPrice
{
class Price
{
const int maximumLineNumber = 50;
const int pageLength = 20;
const int pricePerLicense = 1100;
const int packageOfLicenses = 10;
static void Main()
{
int lineNumber;
int quantityOfLicenses;
int totalForLicenses;
int pricePerLicense;
int maximumLineNumber;
int pageLength;
int packageOfLicenses;
Console.Write("Enter a price per license: ");
if (!int.TryParse(Console.ReadLine(), out pricePerLicense))
{
pricePerLicense = Price.pricePerLicense;
Console.WriteLine("Automatically the price per license is: " + pricePerLicense);
Console.WriteLine();
}
Console.Write("Enter a maximum line number: ");
if (!int.TryParse(Console.ReadLine(), out maximumLineNumber))
{
maximumLineNumber = Price.maximumLineNumber;
Console.WriteLine("Automatically the maximum line number is: " + maximumLineNumber);
Console.WriteLine();
}
Console.Write("Enter a page length per output: ");
if (!int.TryParse(Console.ReadLine(), out pageLength))
{
pageLength = Price.pageLength;
Console.WriteLine("Automatically the page length per output is: " + pageLength);
Console.WriteLine();
}
Console.Write("Enter a package of licenses: ");
if (!int.TryParse(Console.ReadLine(), out packageOfLicenses))
{
packageOfLicenses = Price.packageOfLicenses;
Console.WriteLine("Automatically the package of licenses is: " + packageOfLicenses);
Console.WriteLine();
}
;
int discount = 3500;
int numberOfLicenses = 1;
for (lineNumber = 1; lineNumber <= maximumLineNumber; lineNumber++)
{
if (packageOfLicenses == (10 * numberOfLicenses))
{
discount = 3500 * lineNumber;
quantityOfLicenses = packageOfLicenses * lineNumber; /* Assuming packageOfLicenses=10, we print price of 10 licenses on line 1, and 20 licenses on line 2, …*/
totalForLicenses = quantityOfLicenses * pricePerLicense;
Console.WriteLine("Line " + lineNumber + ": "
+ quantityOfLicenses + " Licenses "
+ "cost " + (totalForLicenses - discount));
}
if ((lineNumber % pageLength) == 0) Console.ReadKey(); /* pause after every page printed */
}
Console.ReadKey();
}
}
}
请有人帮助我. :(
我需要这样的输出
10个许可证仅售7500
20个许可证仅售15000
第1行:许可PHP 1100
第2行:许可证PHP 2200
第3行:许可证PHP 3300
第4行:许可证PHP 4400
第5行:许可证PHP 5500
第6行:许可证PHP 6600
第7行:许可证PHP 7700
第8行:许可证PHP 8800
第9行:许可证PHP 9900
第10行:许可证PHP 7500
第11行:许可证PHP 8600
第12行:许可证PHP 9700
:
第300行许可证PHP….
please someone help me with this. :(
i need the output like this
10 licenses costs only 7500
20 licenses costs only 15000
line 1: licence PHP 1100
line 2: licenses PHP 2200
line 3: licenses PHP 3300
line 4: licenses PHP 4400
line 5: licenses PHP 5500
line 6: licenses PHP 6600
line 7: licenses PHP 7700
line 8: licenses PHP 8800
line 9: licenses PHP 9900
line 10: licenses PHP 7500
line 11: licenses PHP 8600
line 12: licenses PHP 9700
:
line 300 licenses PHP ….
推荐答案
这甚至不应该编译,因为您已经两次声明了一些变量.
This shouldn''t even compile because you''ve declared some of the variables twice.
const int maximumLineNumber = 50;
const int pageLength = 20;
const int pricePerLicense = 1100;
const int packageOfLicenses = 10;
static void Main()
{
int maximumLineNumber;
int pageLength;
int pricePerLicense;
int packageOfLicenses;
删除您的const
定义.它们是完全不必要的.
Delete your const
definitions. They''re completely unnecessary.
只需更改这大部分并可以正常工作
Just change this much part and its working fine
int discount = 3500;
int numberOfLicenses = 1;
string val = "";
for (lineNumber = 1; lineNumber <= maximumLineNumber; lineNumber++)
{
if (packageOfLicenses == (10 * numberOfLicenses))
{
discount = 3500 * lineNumber;
quantityOfLicenses = packageOfLicenses * lineNumber; /* Assuming packageOfLicenses=10, we print price of 10 licenses on line 1, and 20 licenses on line 2, …*/
totalForLicenses = quantityOfLicenses * pricePerLicense;
if (lineNumber % 10 == 0)
{
val = val + "\n Line " + lineNumber + ": "
+ quantityOfLicenses + " Licenses " +
"cost " + (totalForLicenses - discount);
}
}
if ((lineNumber % pageLength) == 0) Console.ReadKey(); /* pause after every page printed */
}
Console.Write(val);
Console.ReadKey();
}
这篇关于C#的简单代码,请帮助我:(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!