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:
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;
}
}
+ 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!
+ 2
so where do you need help here... u got the logic...
+ 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..
+ 1
take a new variable in the while loop... read the value into it, then compare that to maxBid..
+ 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;
}
}
}
}
}
0
NaSaPaKri could you show me an example ?
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.
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;
}
}
}
}
}
0
Write a program to take the maximum bid as input, then take all bids from auction participants until the maximum bid is exceeded.
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
- 1
NaSaPaKri thank you for the help.
like this?
https://code.sololearn.com/cePdDha7zSWb/?ref=app