0

Break / continue question help

Write a program to take the maximum bid as input, then take all bids from auction participants until the maximum bid is exceeded. The program should output the corresponding message with the winning bid. Sample Input 1600 800 1300 1700 Sample Output “Sold: 1700” Hint In order to make continuous input acceptance you need to use while(true) condition. For example, this part of code takes inputs infinitely: In the example, this question already has typed out : Int maxBid=Convert.ToInt32(Console.ReadLine());

2nd Feb 2021, 7:10 PM
Brent Tyson
Brent Tyson - avatar
5 ответов
+ 3
Brent Tyson Show your attempts.
2nd Feb 2021, 7:44 PM
A͢J
A͢J - avatar
+ 3
Brent Tyson 1 - You have to consider 1st bid as a max bid 2 - you need to take rest input inside while loop 3 - continue will skip each iteration and will not print anything so you need to use break instead of continue. First print the value then break loop //your code goes here int maxBid = Convert.ToInt32(Console.ReadLine()); while(true) { int bid = Convert.ToInt32(Console.ReadLine()); if(bid > maxBid) { Console.WriteLine("Sold: " + bid); break; } }
3rd Feb 2021, 4:00 AM
A͢J
A͢J - avatar
0
Learn while loops and how to take user input in C#
3rd Feb 2021, 2:38 AM
Sonic
Sonic - avatar
0
I Am AJ ! 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 maxBid = Convert.ToInt32(Console.ReadLine()); //your code goes here while(true) { if(maxbid >= 1700) { continue; Console.WriteLine("Sold: {0}", maxBid); } } } } }
3rd Feb 2021, 2:55 AM
Brent Tyson
Brent Tyson - avatar
0
Sonic thank you. if you don’t mind, would you care to show me an example from the question i posted?
3rd Feb 2021, 2:57 AM
Brent Tyson
Brent Tyson - avatar