私はプログラミングが初めてで、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 { クラス プログラム { static void 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();
}
}
}