0

Need help for C# practice 18.3

Hi everyone, If anyone have done the practice 18.3 please show me how, I have been working for over 1 hour and still don't get it, Thanks a lot A store is running a unique promotion. If an item's price is an odd number, the item is free. The program you are given takes the number of purchased items as input, followed by the prices of each of the items, then outputs the total amount. Modify the code to skip the odd prices and exclude them in total amount calculation. Sample Input 3 140 235 100 Sample Output 240 Explanation The first input represents the number of purchased items, followed by their prices. Because 235 is an odd number, only 140 and 100 should be summed: 140+100 = 240.

28th Sep 2021, 11:30 AM
Tim Tam
6 Answers
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[ ] n = {3,140,235,100}; int final = 0; for (int x = 0; x<n.Length; x++) { if (n[x]%2==0) { final+=n[x]; } } Console.WriteLine(final); } } } I dont know how its done in the practice but heres something
28th Sep 2021, 7:50 PM
ITDW
0
Please post your attempt....
28th Sep 2021, 12:33 PM
Jayakrishna 🇼🇳
0
Hint: <price> % 2 yields non zero value when <price> is an odd value.
28th Sep 2021, 1:52 PM
Ipang
0
Thank you guy
28th Sep 2021, 9:32 PM
Tim Tam
0
if ((price%2) == 0){ totalAmount += price; }
30th Nov 2021, 3:32 PM
Brian Gomes
Brian Gomes - avatar