Stuck on a C# Pro exercise Problem... | Sololearn: Learn to code for FREE!

+1

# Stuck on a C# Pro exercise Problem...

You are organizing a birthday party and need N number of balloons. You already have 14 balloons for decoration. The given program takes the N required number of balloons as input. Task Calculate and output how many balloons you need to buy. Sample Input 30 Sample Output 16 Explanation The count of the balloons you need to buy is calculated by this formula: balloons-14. So, in this case, the count is 30-14=16. (So I put the code: int x = 30; int y = 14; Console.WriteLine(x-y); And it says I'm correct in answering the first test case, but then there's 2 more test cases below the first that says I'm wrong because I didn't get THEIR outputs. So how do I tweak the code so that I give the correct outputs for all three test cases instead of just getting one test case correct????? )

10/14/2021 8:52:41 PM

Tony Bae

+1

Hello! I see you still have some confusions I can try to clear up. The earlier response from Jayakrishnain was trying to explain that you need to prompt an input in your code. In your program, you hardcoded the values of N number of balloons when you set int x = 30; Instead, you should change it to : int x = Console.ReadLine(); This is because x is a variable we want to change, when you set it to 30, the value remains the same over different tests. You need to prompt input so that you can change this value over tests.

+1

The value 30 is the input there. Not a constant value for all test cases. It may vary (40 0r 80 or any value) So must take that input into x. Know about how to take input values. hope it helps..

+1

Tony Bae Ok. You may have just begin the language. so then try to explain some more details.. The answer you need is : int x = Convert.ToInt32(Console.ReadLine()); This readLine() method read a line from input console but in string farmat. So you need to convert to destination x type of int . So line does this job. That's the whole answer you need there. Its all you can find in lesson. For more info ,read lesson about input taking.. Hope it helps...

+1

//Tony Bae this expected there.. //your code goes here , int x = Convert.ToInt32(Console.ReadLine()); int x =14; //not 16 Console.WriteLine(x-y);

0

Anyone else have any advice that's less circular? I appreciate the help but, brick wall advice isn't helping. I guess I should've posted but I figured it would've been obvious that i tried changing the value of x and it's the same. Only one test case comes out correct at a time. And if that's not what you were implying, then your explanation is formatted in a way that speaks to me in circles. Sorry, gonna need a more clear cut explanation from you or someone else.

0

Arg, must not know the proper way of putting it into the prompt because all I get is error for input. Thank you for the help though

0

Jayakrishna Nothing aimed towards you man. Just keep getting back errored no matter what I try dude. Not you, just this course. And being a...total beginner, I've read through the info over and over in the lessons and I guess there's just chunks of information that programmers already need to know and isn't implied or displayed. All the advice and answers you gave seemed very helpful but it's still comes back errored for the test cases. Trying to get more direct help from sololearn itself via email

0

Tony Bae can you post total code you are trying..? I thought you are struggling to get correct answer.. so I posted it. If you tried it already then ingore it. edit : btw, "Nothing aimed towards you man." I don't understood this what you about?

0

Jayakrishna Nothing aimed towards you: Not frustrated at you nor saying that the help you were giving is wrong. I'm just incapable of understanding

0

Birthday Party You are organizing a birthday party and need N number of balloons. You already have 14 balloons for decoration. The given program takes the N required number of balloons as input. Task Calculate and output how many balloons you need to buy. Sample Input 30 Sample Output 16 Explanation The count of the balloons you need to buy is calculated by this formula: balloons-14. So, in this case, the count is 30-14=16. And underneath //your code goes here I've tried: int x = Convert.ToInt32(Console.ReadLine()); and int x = Console.ReadLine(); and way earlier before I asked for advice I put: int x = 30; int x =16; Console.WriteLine()x-y; < But earlier found out this was wrong also