Going once, Going twice, Sold. | SoloLearn: Learn to code for FREE!

0

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); } } } }

c#

4/12/2021 4:59:46 AM

Andrew Hall

11 Answers

New Answer

+2

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.

+1

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.

+1

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>) 👍

+1

`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); } } }

+1

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

+1

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.

+1

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!

+1

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)

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?

0

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.

0

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.