+ 4

Going once, Going twice, Sold.

ive been trying to complete this task for a couple of days now, but its stumping me. i feel like the app hasn't given me quite enough information to fill in those last few blanks, and i could use the communities help please. the task states: we are making a program for auction with a maximum bid set. The count of bid 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 by all participants. the last participant suggested a bid (1700) which is above the minimum bid (1600) and won the auction. thus that bid is output. hint in order to make continuous input acceptance you need to use the while (true) condition. for example, this part of the code takes inputs infinitely. while (true) { string smth = console.ReadLine (); } use an if statement inside the loop to execute the brake condition. my current effort looks like this (though this is just one of a bunch of different ways ive tried to arrange it with no success so far) namespace sololearnpractise { class Program { static void Main(string[] args) { int maxBid = Convert.ToInt32(Console.ReadLine()); while (maxBid <1600) { string smth = Console.ReadLine(); if (maxBid >= 1600) break; Console.WriteLine ("Sold: " + maxBid); } } } }

12th Apr 2021, 4:59 AM
Andrew Hall
Andrew Hall - avatar
18 Réponses
+ 6
It tells you right in the explanation to use; while (true) { // get current bid as int // Check if current bid is greater than // Or equal to max bid, break if true } And to use the if statement to check if the bid is greater than the max bid. if (currentBid >= maxBid) break; Then your output should be after and outside the while loop and be as shown in the example including spelling, case, spacing and punctuation etc. Also, given that the output will contain the current bid that is greater than or equal to the max bid, think about where you will need to declare the variable so that it is within scope of both the while loop and the output statement.
12th Apr 2021, 5:17 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Andrew Hall please reread my previous post. Here is some pseudocode for how the code inside the main method should be. Get maxBid as int from input Declare currentBid as int while true { Set value of currentBid from input as int Check if currentBid >= maxBid If true break from the loop } Output "sold " + currentBid
12th Apr 2021, 9:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
It's very close. Inside the while loop, where you have 1600 hard coded, replace that with another input (same as what you have for maxBid). In the if statement remove the line setting currentBid to maxBid and just leave the break. Then in your output change maxBid to currentBid. Some of the confusion is that we gave you 2 close, but slightly different, solutions. Make these changes and try it. If it isn't passing, post your updated code again. Make sure that the output matches the same as what it is expecting as far as whether it should be "Sold: " or "sold " etc since we can't see what is expected, not having a pro subscription.
14th Apr 2021, 5:52 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Ive tried, the while (true) line in a few attempts (i assumed by “true” it meant if this is true, rather than literally the word true when it didnt seem to work). Ive as yet, never tried including a currentbid varable though. Ill have a look at including that now. Thank you.
12th Apr 2021, 5:27 AM
Andrew Hall
Andrew Hall - avatar
+ 2
Just adding a little to ChaoticDawg, before you break out of the loop, be sure to set <maxBid> to the value of last bid read inside the loop body (the one that is greater than <maxBid>) 👍
12th Apr 2021, 5:34 AM
Ipang
+ 2
`Console.ReadLine()` method returns a string. `ConvertToInt32()` method converts the given string (from Console.ReadLine()) into an integer. <smth> must be an int to compared to <maxBid>. using System; namespace SololearnPractice { class Program { static void Main(string[]args) { // assume 1st input as highest bid <maxBid> int maxBid = Convert.ToInt32(Console.ReadLine()); while (true) { // <bid> is another input we read in loop // to be compared against <maxBid> later on int bid = Convert.ToInt32(Console.ReadLine()); // is <bid> greater than <maxBid>? if (bid > maxBid) { // update <maxBid> value to that of <bid> maxBid = bid; break; } } // print <maxBid> outside while-loop body Console.WriteLine("Sold: " + maxBid); } } }
12th Apr 2021, 9:30 AM
Ipang
+ 2
actually. after re-reading my own post ive figured it out! the code below meets the conditions of the challenge! namespace SoloLearn { class Program { static void Main(string[] args) { int maxBid = Convert.ToInt32 (Console.ReadLine()); int currentBid; while (true) { currentBid =1600; if (maxBid >= currentBid) { currentBid = maxBid; break; } } Console.WriteLine ("sold: " + maxBid); } } } cheers guys!
14th Apr 2021, 5:54 AM
Andrew Hall
Andrew Hall - avatar
+ 2
solved it for real this time! this code will pass the challenge. namespace SoloLearn { class Program { static void Main(string[] args) { int maxBid = Convert.ToInt32(Console.ReadLine()); int currentBid; while (true) { currentBid = Convert.ToInt32(Console.ReadLine()); if (maxBid < currentBid) { break; } } Console.WriteLine("Sold: " + currentBid); } } } thanx guys, and especially thanx to Chaoticdawg for sticking with it, while i rambled on lol. and yeah btw, the S in sold needed to be capitalised. (i knew this, it just slipped through lol)
15th Apr 2021, 5:42 AM
Andrew Hall
Andrew Hall - avatar
+ 2
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 i = 0; while (i < maxBid) { string smth = Console.ReadLine(); if (Convert.ToInt32(smth) > maxBid) { Console.WriteLine("Sold: " + smth); break; } } } } }
22nd Aug 2021, 4:01 PM
Yousif R Wali
Yousif R Wali - avatar
+ 1
after another few hours of banging my head against this, im still no further forward. this is my current iteration (of many that hasent worked) namespace SoloLearn { class Program { static void Main(string[] args) { int maxBid = Convert.ToInt32 (Console.ReadLine ()); int currentBid; while (true) { currentBid = 1600; if (currentBid >= maxBid) { currentBid = maxBid; break; } } Console.WriteLine ("Sold: " + maxBid); } } } this iteration is simply outputting whatever value i input alongside the word sold: (as have a few varients ive tried) and seems to be bypassing the while loop entirely. ive tried interpreting what people have written here and implementing it (thanks for those suggestions) but i cant seem to get those explanations to work. at this point id really appreciate if someone could post an example of code that has passed this particular challenge, because while id like to get to the bottom of this thing, im wasting my time trying to figure it out when i could be spending that time learning the next stages. cheers.
14th Apr 2021, 5:39 AM
Andrew Hall
Andrew Hall - avatar
+ 1
the code above worked for how i interpreted the challenge. which im happy about because thats what ive been trying to do. unfortunately, i interpreted the challenge wrong lol. i thought that 1600 mentioned was a reserve, but in retrospect it seems it was an initial bid. bit of a strange way to run an auction, but ill go with it lol. its time for work now. ill have another look later.
14th Apr 2021, 6:06 AM
Andrew Hall
Andrew Hall - avatar
+ 1
you can use generic list to easy handle List<int> Prices = new List<int>(); int nTopPrice = 0; while (true) { Console.Write("Pleas Type your Price: "); int nPrice = int.Parse(Console.ReadLine()); Prices.Add(nPrice); Prices.Sort(); Prices.Reverse(); if (Prices[0] == nPrice) { Console.WriteLine("You Win!!"); nTopPrice = nPrice; } Console.WriteLine("Top Price Is " + nTopPrice.ToString()); }
19th Sep 2021, 3:46 PM
Bashir Sarraj
Bashir Sarraj - avatar
+ 1
this is the code that worked for me: int maxBid = Convert.ToInt32(Console.ReadLine()); while (true==true) { int bid=Convert.ToInt32(Console.ReadLine()); if (bid>=maxBid) { Console.WriteLine("Sold: {0}", bid); break; } }
27th Jan 2022, 8:27 PM
Ania
+ 1
you can reject when last input(temp) is less then or equal second last input(current last max input) and last input always be Max. I don't know much about C# but you can use this type of algorithm :)
30th Nov 2022, 7:58 AM
RTB
RTB - avatar
+ 1
very well
12th Dec 2023, 2:57 PM
Pablo Vidal Ortega, 1 DAM
Pablo Vidal Ortega, 1 DAM - avatar
0
so this is my current iteration, though i feel ive just said the same thing in a different way, and got the same result: no output. namespace sololearnpractise { class Program { static void Main(string[] args) { int currentBid = Convert.ToInt32(Console.ReadLine()); int maxBid = 1600; while (true) { string smth = Console.ReadLine(); if (currentBid >= maxBid) break; Console.WriteLine ("Sold: " + currentBid); } } } } the task is asking for a program that continuously takes inputs and does nothing until one of those inputs exceeds the minimum requirement, then we get a sold output. im also not sure exactly how the line: string smth = Console.ReadLine(); works. am i using it correctly here? what does smth represent? (thats how it was given in the hint) does it do its job as is, or does that "smth" represent something i was supposed to change?
12th Apr 2021, 6:02 AM
Andrew Hall
Andrew Hall - avatar
0
no worries all good
12th Sep 2022, 10:56 AM
RANJITH KUMAR C
RANJITH KUMAR C - avatar