compiler construction - C# Console Error: Only assignment, call, increment, decrement, and new object expressions can be used as a statement -
i new programming , attempting learn c#. having think simple problem console application(the code below). error appears if statement reads follows:
//evaluate subtotals results if (subtotalone == subtotaltwo) { console.writeline("="); } else if (subtotalone < subtotaltwo) { console.writeline("<"); } else (subtotalone > subtotaltwo); { console.writeline(">"); }
the error is: assignment, call, increment, decrement, , new object expressions can used statement.
any appreciated. have read through forums here , seen may similar questions understanding isn't enough yet map solutions i've seen problem.
full application code:
using system;
namespace itc110_a02_grocerycomparison { class program { static void main(string[] args) {
console.writeline("compare grocery stores "); //alert user purpose of program title console.writeline("\n");//line break // store 1 console.writeline("enter name of first store comparison: ");//storename 1 string storeone = console.readline();//tolower eval //store 1, first item console.writeline("name of first product purchased @ " + storeone + ": ");//ask item string purchaseone = console.readline();//collect item console.writeline("price paid first purchased @ " + storeone + ": ");//ask 1st price double price1a = double.parse(console.readline());//collect 1st price //store 1, second item, repeat process -- ought method or function console.writeline("name of second product purchased @ " + storeone + ": ");//ask item string purchasetwo = console.readline();//collect item console.writeline("price paid second purchased @ " + storeone + ": ");//ask item price double price1b = double.parse(console.readline());//collect item price console.writeline("\n"); // store 2, repeat process -- ought method or function console.writeline("enter name of second store comparison: ");//store name 1 string storetwo = console.readline();// evals entry, tolower set lower case //store 2 console.writeline("price paid " + purchaseone + " @ " + storetwo + ": ");//ask 1st price double price2a = double.parse(console.readline());//collect 1st price //store 2, second item console.writeline("price paid " + purchasetwo + " @ " + storetwo + ": ");//ask item price double price2b = double.parse(console.readline());//collect item price console.writeline("\n"); // results go here //store 1 totals console.writeline("************ " + storeone + " ************"); console.writeline(purchaseone + ": $" + price1a); console.writeline(purchasetwo + ": $" + price1b); console.writeline("\n \n"); // store 2 totals console.writeline("************ " + storetwo + " ************"); // result a: 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 results if (subtotalone == subtotaltwo) { console.writeline("="); } else if (subtotalone < subtotaltwo) { console.writeline("<"); } else (subtotalone > subtotaltwo); { console.writeline(">"); } //keeps console open console.read(); } }
}
this else
line problem.
else (subtotalone > subtotaltwo); { console.writeline(">"); }
fixed:
else { console.writeline(">"); }
explanation:
your code equivalent to:
else (subtotalone > subtotaltwo);//else block { console.writeline(">"); }
semicolon makes condition expression statement , error. however, next console statement not part of else block else block finishes after semicolon. so, if condition expression valid statement, ">" printed not desired.
Comments
Post a Comment