0

Break and continue

Working on loops, im at the break and continue portion where it gives me multiple numbers for input and my code should find the largest and use it for output, the output should be “Sold:(highest input)” I do not have it set to insert the text becAuse i was more focusing on the output number then id plug in the text but its outputting all input numbers in one sequence 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 x= 1; while(true) { int maxBid = Convert.ToInt32(Console.ReadLine()); if (maxBid == x) break; Console.Write(maxBid); } } } }

28th Oct 2020, 2:50 AM
Da SplitUpNinja
Da SplitUpNinja - avatar
2 Answers
+ 2
Your code prints every number inputted until finding "1". It looks like you want to calculate maximum. The following should be closer to what you want: using System; namespace SoloLearn { class Program { static void Main(string[] args) { int x= 1; int maxBid = -1; while(true) { int newInput = Convert.ToInt32(Console.ReadLine()); if (newInput == x) break; if (newInput > maxBid) maxBid = newInput; } Console.Write("Sold:" + maxBid); } } }
28th Oct 2020, 4:06 AM
Josh Greig
Josh Greig - avatar
0
Josh Greig this really helped however had to bump x=1 to x=0 and made y as 1 and BOOM but i knew i was missing a factor and even felt like i had to make another “if” and at one point thought i needed another int but again thank you for steering me the right way!
28th Oct 2020, 5:09 AM
Da SplitUpNinja
Da SplitUpNinja - avatar