Stuck on a C# Pro exercise Problem... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

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

14th Oct 2021, 8:52 PM
Tony Bae
12 Answers
- 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.
15th Oct 2021, 3:28 AM
Jibraeel Abdelwahhab
Jibraeel Abdelwahhab - avatar
+ 1
int balloons = Convert.ToInt32(Console.ReadLine()); //your code goes here int sol1 = balloons; int x = 14; int sol2 = balloons - x; Console.WriteLine(sol2); Try this.
17th Dec 2021, 2:37 PM
Musa
0
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..
14th Oct 2021, 8:59 PM
Jayakrishna 🇮🇳
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.
14th Oct 2021, 11:09 PM
Tony Bae
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
15th Oct 2021, 6:53 PM
Tony Bae
0
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...
15th Oct 2021, 7:18 PM
Jayakrishna 🇮🇳
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
15th Oct 2021, 7:33 PM
Tony Bae
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?
15th Oct 2021, 7:37 PM
Jayakrishna 🇮🇳
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
15th Oct 2021, 7:44 PM
Tony Bae
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
15th Oct 2021, 7:48 PM
Tony Bae
0
//Tony Bae this expected there.. //your code goes here , int x = Convert.ToInt32(Console.ReadLine()); int x =14; //not 16 Console.WriteLine(x-y);
15th Oct 2021, 7:57 PM
Jayakrishna 🇮🇳
0
This line “int balloons = Convert.ToInt32(Console.ReadLine());” Already determines the input so we just have to insert the number it has to subtract. So 14 is x. //your code goes here int x = 14; Console.WriteLine(balloons-x);
3rd Feb 2022, 5:03 AM
Sang Van Le