0

Continue & break

Working on break and continues and the try it yourself wants me to skip odd numbers that are being input and ive tried a hundred different ways and can only skip the 1st number when i try to modify the code in the example i can get it to skip the odds but not in try it yourself. This is my most recent attempt If you can help as well as explain the answer thatd be appreciated 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 amount = Convert.ToInt32(Console.ReadLine()); int count = 0; int totalAmount = 0; while (count<amount) { count++; int price = Convert.ToInt32(Console.ReadLine()); /* starts me after price input line and states to skip odd numbers*/ for (;price < 10; price++) if (++price == 1) continue; totalAmount += price; } Console.WriteLine(totalAmount); } } }

30th Oct 2020, 5:07 PM
Da SplitUpNinja
Da SplitUpNinja - avatar
2 odpowiedzi
0
Can you add a sample input, output to understand what you trying..? If you want skip odd numbers, you shloud do like if(prime%2==1) continue;
30th Oct 2020, 8:55 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 funny thing was i tried it like that at one point but didnt notice another piece of my code countering it so thank you you had me reevaluate what i did wrong when i tried this the first time lol just another “wow it was that simple” moments
30th Oct 2020, 9:26 PM
Da SplitUpNinja
Da SplitUpNinja - avatar