+ 2
How can I successfully solve 3 cases (with the same format but varying numbers) from one program?
I can solve case1, case2, and case3 individually but am receiving errors when solved all at the same time. Relevant Example Case1 int balloons = 30; Console.Write(balloons-14); Output=16 Case2 int balloons = 42 Console.Write(balloons-14) Case3 int balloons = 32 Console.Write(balloons-14) I get case1 right with output = 16, but the other 2 cases error out because the numbers are different....
20 Answers
+ 4
Don't hard-code balloons. Rather take input, convert it to integer and store it as balloons
+ 3
User input is explained in lesson 5. You can re-read previous lessons as often as you like.
Here is an illustration of my explanation
https://code.sololearn.com/cEKs8RSWrDDW/?ref=app
+ 2
Instead of giving manual values, take input from user.. learn about ' taking user input '
int balloons = Convet.Toint32 ( Console. readLine()) ;
+ 2
Okay, I see. You tried to write 3 programms.
You only need 1 program (delete the others). Then save the input (that's the Convert.ToInt32(...) thing) to an integer variable and use this variable for your calculation.
+ 2
"Input" here means we get a number from a person: sololearn bot acts as a "person" who types in a number. It can be 30 or 33 or whatever. We need to write the program without knowing which number the "user" gives us.
But we can create a variable that holds the input number and use that for our calculation!
int myinput = Convert.ToInt32(Console.ReadLine());
Now we have a number and use it like this:
Console.WriteLine(myinput+100);
Now the output is the input + 100. So if we input 30, the output will be 130 and we only need 1 program to handle all input numbers.
+ 2
Thank you, I'll do that, but the point was accomplished in case1. Your soultion is another lesson entirely; sort of like a hidden symbolic constant for recall and editing which was not defined or taught as a prerequisite for completing this lesson
+ 1
This line
Convet.Toint32 ( Console. readLine()) ;
takes the input but you are not storing the value. Store it in a variable and use it in calculation.
Like :
int balloons = Convet.Toint32 ( Console. readLine()) ;
Use this balloons in calculation.
No need other programs..
+ 1
It's explained in lesson 5.1 and now your exercise is from 9.1 lesson (am I correct?) So you revise back..
It just run multiple times with different input values, not in a single time. You can the code by running multiple times.. Hope you can solve or solved it now.. !!
+ 1
These are only EXAMPLE INPUTS. There will be only ONE input at a time.
+ 1
I just passed!!! Someone reviewed my code earlier with all the valid inputs and outputs. Thank you for your time!!!
0
Lisa, I did...
0
Blake Smith Your given code doesn't show any attempt for getting input. Could you please link your updated code?
0
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:
0
I did... It failed me.
0
That's why I wrote 3
0
I actually wrote 4 or 5 valid programs and only 3 passed me on case 1
0
The course did not explain how to utilize Convet. Toint32 ( Console. readLine());
0
My first input worked and gave me a passing output mark for case 1. The other 2 haven't worked because the int balloons value changes in each case...
0
Regardless there are 3 different case examples, and Sololearn wants all of them completed at the same time with varying answers but with only one row/solution of numbers.... There are three different output numbers required for each case, and I solved all three earlier individually and together, but each one conflicted with one another when solved together, but individually only solved for one at a time. It requires the answers all at the same time in order to pass. It's been a catch 22....
- 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program1
{
static void Main([]string args)
{
Convert.ToInt32(Console.ReadLine());
int nballoons = 30;
int b = 14;
Console.WriteLine(nballoons-b);
}
}
}
namespace SoloLearn
{
class Program2
{
static void Main(string[] args)
{
Convert.ToInt32(Console.ReadLine());
int nballs = 40;
int b = 14;
Console.WriteLine(nballs-b);
}
}
}
namespace SoloLearn
{
class Program3
{
static void Main(string[] args)
{
Convert.ToInt32(Console.ReadLine());
int nball = 32;
int b = 14;
Console.WriteLine(nball-b);
}
}
}