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());
5 Réponses
+ 3
Brent Tyson Show your attempts.
+ 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;
}
}
0
Learn while loops and how to take user input in C#
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);
}
}
}
}
}
0
Sonic thank you. if you don’t mind, would you care to show me an example from the question i posted?