我是编程新手,正在尝试学习 c#。我的控制台应用程序遇到了我认为是一个简单的问题(代码如下)。该错误似乎与我的 if 语句有关,内容如下:
//evaluate subtotals to results
if (subTotalOne == subTotalTwo)
{
Console.WriteLine("=");
}
else if (subTotalOne < subTotalTwo)
{
Console.WriteLine("<");
}
else (subTotalOne > subTotalTwo);
{
Console.WriteLine(">");
}
我得到的错误是:只有赋值、调用、递增、递减和新对象表达式可以用作语句。
任何帮助,将不胜感激。我已经阅读了这里的论坛并看到了可能类似的问题,但我的理解还不足以将我看到的解决方案映射到我的问题。
完整应用代码:
using System;
命名空间 itc110_a02_GroceryComparison { 类程序 { 静态无效 Main(string[] args) {
Console.WriteLine("Compare Grocery Stores "); //Alert user to purpose of program with title
Console.WriteLine("\n");//line break
// Store 1
Console.WriteLine("Enter the name of the first store for comparison: ");//storeName 1
String storeOne = Console.ReadLine();//ToLower for eval
//store 1, first item
Console.WriteLine("Name of First product purchased at " + storeOne + ": ");//ask item
String purchaseOne = Console.ReadLine();//collect item
Console.WriteLine("Price paid for first purchased at " + storeOne + ": ");//ask 1st price
Double price1A = Double.Parse(Console.ReadLine());//collect 1st price
//store 1, second item, repeat process -- this ought to be a method or a function
Console.WriteLine("Name of second product purchased at " + storeOne + ": ");//ask item
String purchaseTwo = Console.ReadLine();//collect Item
Console.WriteLine("Price paid for second purchased at " + storeOne + ": ");//Ask Item Price
Double price1B = Double.Parse(Console.ReadLine());//Collect Item Price
Console.WriteLine("\n");
// Store 2, repeat process -- this ought to be a method or a function
Console.WriteLine("Enter the name of the second store for comparison: ");//Store name 1
String storeTwo = Console.ReadLine();// To Evals entry, we ToLower to set to lower case
//store 2
Console.WriteLine("Price paid for " + purchaseOne + " at " + storeTwo + ": ");//ask 1st price
Double price2A = Double.Parse(Console.ReadLine());//collect 1st price
//store 2, second item
Console.WriteLine("Price paid for " + purchaseTwo + " at " + storeTwo + ": ");//Ask Item Price
Double price2B = Double.Parse(Console.ReadLine());//Collect Item Price
Console.WriteLine("\n");
// Results go here
//Store one totals
Console.WriteLine("************ " + storeOne + " ************");
Console.WriteLine(purchaseOne + ": $" + price1A);
Console.WriteLine(purchaseTwo + ": $" + price1B);
Console.WriteLine("\n \n");
// store two totals
Console.WriteLine("************ " + storeTwo + " ************");
// Result A: Where to shop
Console.WriteLine(purchaseOne + ": $" + price2A);
Console.WriteLine(purchaseTwo + ": $" + price2B);
Console.WriteLine("\n \n");
Console.WriteLine("************ After Price Comparison ************");
//merge subtotals
Double subTotalOne = (price1A + price1B);
Double subTotalTwo = (price2A + price2B);
//evaluate subtotals to results
if (subTotalOne == subTotalTwo)
{
Console.WriteLine("=");
}
else if (subTotalOne < subTotalTwo)
{
Console.WriteLine("<");
}
else (subTotalOne > subTotalTwo);
{
Console.WriteLine(">");
}
//keeps the console open
Console.Read();
}
}
}