模块化程序错误 [英] Modular Programm Error
本文介绍了模块化程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我已经完成了我的程序,但它无法编译。我检查了花括号,它们都是对齐的。但是,我收到最后一个大括号的错误(类型或命名空间定义,或预期的文件结束)。我确信这与模块有关,但此时我不知道那可能是什么。任何有关这方面的帮助将不胜感激。谢谢
Hello I have most completed my program and yet it will not compile. I have checked out the curly braces and they are all aligned. However, I am receiving an error from the very last curly brace stating (Type or namespace definition, or end of file expected). I am sure that this has something to do with the modules, but at this point I don't know what that might be. Any help with this would be greatly appreciated. Thanks
namespace VS_Sand_Box
{
class Program
{
static void Main(string[] args)
{
//Enter Varibales
string customerName, customerState;
int unitAmount;
double unitPrice, totalPrice, totalTax;
//Gather user input
Console.Write("Enter the customer's name: ");
customerName = Console.ReadLine();
Console.Write("Enter the location of transaction i.e.(NJ, FL, or NY): ");
customerState = Console.ReadLine();
Console.Write("Enter the amount of units being purchased: ");
unitAmount = Int32.Parse(Console.ReadLine());
Console.Write("Enter the price per unit: ");
unitPrice = Double.Parse(Console.ReadLine());
//Jump to Module 1
totalPrice = computeTotal(unitAmount, unitPrice);
//Jump to Module 2
totalTax = computeTax(totalPrice, customerState);
//Continue with output
Console.WriteLine( "\n\nThe total sales for" + customerName + " are " + totalPrice.ToString("C2"));
Console.Write("The tax amount is " + totalTax.ToString("C2"));
Console.WriteLine( "\nThe total with tax is $" +(totalTax + totalPrice));
Console.ReadLine();
}
//Module 1
public static double computeTotal (int qty, double price)
{
return (qty * price);
}
//Module 2
public static double computeTax (double totalPrices, string customerState)
{
if (customerState == "NJ")
return totalPrices * .07;
else if (customerState == "FL")
return totalPrices * .04;
else if (customerState == "NY")
return totalPrices * .06;
else
return 0;
}
}
}
//Error!!! Type namespace definition, or end-of-file expecedted Error!!!
}
推荐答案
+(totalTax + totalPrice));
Console.ReadLine();
}
// 第1单元
public static double computeTotal( int qty, double 价格)
{
return (qty * price);
}
// 模块2
public static double computeTax( double totalPrices,串跨度> customerState)
{
if (customerState == NJ)
return totalPrices *。 07 ;
else if (customerState == FL)
return totalPrices *。 04 跨度>;
else if (customerState == NY)
return totalPrices *。 06 跨度>;
else
return 0 跨度>;
}
}
}
// 错误!键入命名空间定义,或者文件结束时出错!!!
}
" +(totalTax + totalPrice)); Console.ReadLine(); } //Module 1 public static double computeTotal (int qty, double price) { return (qty * price); } //Module 2 public static double computeTax (double totalPrices, string customerState) { if (customerState == "NJ") return totalPrices * .07; else if (customerState == "FL") return totalPrices * .04; else if (customerState == "NY") return totalPrices * .06; else return 0; } } } //Error!!! Type namespace definition, or end-of-file expecedted Error!!! }
<pre lang="text"><pre lang="cs">namespace VS_Sand_Box
{
class Program
{
static void Main(string[] args)
{
{
//Enter Varibales
string customerName, customerState;
int unitAmount;
double unitPrice, totalPrice, totalTax;
//Gather user input
Console.Write("Enter the customer's name: ");
customerName = Console.ReadLine();
Console.Write("Enter the location of transaction i.e.(NJ, FL, or NY): ");
customerState = Console.ReadLine();
Console.Write("Enter the amount of units being purchased: ");
unitAmount = Int32.Parse(Console.ReadLine());
Console.Write("Enter the price per unit: ");
unitPrice = Double.Parse(Console.ReadLine());
//Jump to Module 1
totalPrice = computeTotal(unitAmount, unitPrice);
//Jump to Module 2
totalTax = computeTax(totalPrice, customerState);
//Continue with output
Console.WriteLine("\n\nThe total sales for " + customerName + " are " + totalPrice.ToString("C2"));
Console.Write("The tax amount is " + totalTax.ToString("C2"));
Console.WriteLine("\nThe total with tax is
+(totalTax + totalPrice));
Console.ReadLine();
}
}
// 第1单元
public static double computeTotal ( int qty, double price)
{
返回(数量*价格);
}
// 模块2
< span class =code-keyword> public static double computeTax( double totalPrices, string customerState)
{
if (customerState == NJ)
return totalPrices *。 07 ;
else if (customerState == FL)
return totalPrices *。 04 跨度>;
else if (customerState == NY)
return totalPrices *。 06 跨度>;
else
return 0 跨度>;
}
}
}
" + (totalTax + totalPrice)); Console.ReadLine(); } } //Module 1 public static double computeTotal (int qty, double price) { return (qty * price); } //Module 2 public static double computeTax (double totalPrices, string customerState) { if (customerState == "NJ") return totalPrices * .07; else if (customerState == "FL") return totalPrices * .04; else if (customerState == "NY") return totalPrices * .06; else return 0; } } }
这篇关于模块化程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文