Help please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help please

We are making a program for auction with a maximum bid set. The count of bids is variable. 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 Explanation The first input represents the maximum bid, followed by the bids offered from all participants. The last participant suggested a bid (1700) which is above the maximum (1600) and won the auction. Thus, that bid is outputted. Hint In order to make continuous input acceptance you need to use while(true) condition. For example, this part of code takes inputs infinitely:

10th Feb 2021, 5:11 PM
Brent Tyson
Brent Tyson - avatar
14 Answers
+ 1
int maxBid = Convert.ToInt32(Console.ReadLine()); //your code goes here while(true) { int temp=Convert.ToInt32(Console.ReadLine()); if(temp >= maxBid) { Console.WriteLine("Sold: {0}", temp); break; } }
11th Feb 2021, 5:26 PM
NaSaPaKri
NaSaPaKri - avatar
+ 8
Brent Tyson , before we can help you, please show us your attempt first. please put your code in playground and link it here. thanks!
10th Feb 2021, 9:08 PM
Lothar
Lothar - avatar
+ 2
so where do you need help here... u got the logic...
10th Feb 2021, 6:31 PM
NaSaPaKri
NaSaPaKri - avatar
+ 2
ok, Brent Tyson here we took a while loop which runs infinitely... that is it keeps on taking user inputs... the question here is that whenever there's an bid greater than or equal to maximum bid, u need to stop and print the bid's value and exit out of the loop, that is break the loop ... from your code i can see that u have considered only equal case... and u r breaking the while loop... change the condition to >= and add a break statement when the condition is met after your print statement..
11th Feb 2021, 2:34 AM
NaSaPaKri
NaSaPaKri - avatar
+ 1
take a new variable in the while loop... read the value into it, then compare that to maxBid..
11th Feb 2021, 3:24 AM
NaSaPaKri
NaSaPaKri - avatar
+ 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 maxBid = Convert.ToInt32(Console.ReadLine()); //your code goes here while(true) { int temp=Convert.ToInt32(Console.ReadLine()); if(temp >= maxBid) { Console.WriteLine("Sold: {0}", temp); break; } } } } }
14th Feb 2023, 2:19 PM
Guy Martial KEYOU
0
NaSaPaKri could you show me an example ?
11th Feb 2021, 5:16 PM
Brent Tyson
Brent Tyson - avatar
0
NaSaPaKri thank you so much. It worked! somedays i understand C# and others i dont. im going to keep learning thanks to people like you that help beginners Lol. i also feel like the questions given through SoloLearn dont explain much but i guess thats part of the challenge. Thanks again! im going to study your code snippet provided.
11th Feb 2021, 11:47 PM
Brent Tyson
Brent Tyson - avatar
0
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 int bid = 0; while (true) { bid = Convert.ToInt32(Console.ReadLine()); if (bid>maxBid) { Console.WriteLine("Sold: {0}",bid); break; } } } } }
24th Jul 2021, 6:04 PM
Anubis
0
Write a program to take the maximum bid as input, then take all bids from auction participants until the maximum bid is exceeded.
10th Jun 2022, 2:36 AM
ABDUL ROUF rouf
ABDUL ROUF rouf - avatar
0
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()); int bid = int.Parse(Console.ReadLine()); while(bid<maxBid) { bid = int.Parse(Console.ReadLine()); } //your code goes here Console.WriteLine("Sold: " +bid); } } } // Try not to follow me
22nd Aug 2022, 3:03 AM
Abdul Bari Rahmani
Abdul Bari Rahmani - avatar
- 1
Lothar NaSaPaKri the question also gives me an example of a while( true )statement and also says to ues an if...else statement in the while code block
10th Feb 2021, 11:44 PM
Brent Tyson
Brent Tyson - avatar
- 1
11th Feb 2021, 3:13 AM
Brent Tyson
Brent Tyson - avatar