Practice 13.2 c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Practice 13.2 c#

As I'm learning to program games on unity I used a lot of times if else if statement. But I think in all this time I don't understand nothing idk. Can you guys tell me what is wrong please. 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) { //tomando la edad como entrada int age = 14; Convert.ToInt32(Console.ReadLine()); //tu código va aquí if (age <= 19); { Console.WriteLine("Take your kindle"); } else { Console.WriteLine(" "); } } } }

28th Jun 2022, 1:07 PM
Alex
Alex - avatar
12 Answers
0
Las aerolíneas están ofreciendo una promoción especial para los adolescentes y están ofreciendo libros electrónicos para usar durante el vuelo. Escribe un programa para tomar la edad de cada pasajero como entrada, y generar "Take your kindle", si la edad es menor o igual a 19 años. Ejemplo de entrada 14 Ejemplo de salida Take your kindle If age Is more than 19 console shouldn't print nothing
28th Jun 2022, 1:10 PM
Alex
Alex - avatar
0
With this code only 3 opcións out of 5 are working 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) { //tomando la edad como entrada int age = 14; Convert.ToInt32(Console.ReadLine()); //tu código va aquí if (age <= 19); { Console.WriteLine("Take your kindle"); } } } }
28th Jun 2022, 1:12 PM
Alex
Alex - avatar
0
If the task requires you to read value for variable <age>, then you should do int age = Convert.ToInt32( Console.ReadLine() ); Rather than using hardcoded value (14). If the task requires you to only print output when <age> was less than or equal to 19, then you don't need an `else` block at all.
28th Jun 2022, 2:44 PM
Ipang
0
I tried without the else block and doesn't work
28th Jun 2022, 2:54 PM
Alex
Alex - avatar
0
Pass me the task Description, I need to read it ...
28th Jun 2022, 2:55 PM
Ipang
0
Is in Spanish i write it as answer on top
28th Jun 2022, 2:59 PM
Alex
Alex - avatar
0
Took this from task Description "Write a program to take the age of each passenger as input, and output "Take your kindle", if the age is less than or equal to 19 years." Try to read input for <age> rather than using hardcoded value. If that didn't help we'll talk again.
28th Jun 2022, 3:16 PM
Ipang
0
If you mean to add a value to age i added but doesn't work. With the code If (age <=19) { Console.WriteLine("take your kindle") } Work with ages lower or equal to 19. The problem is when age is bigger than 19 the program doesn't work. This is why I added the "else". To say else { Console.WriteLine(""); } Like this I understand else don't write nothing because age is bigger than 19
28th Jun 2022, 4:19 PM
Alex
Alex - avatar
0
No bro. I was suggesting you to read the value for variable <age> like this int age = Convert.ToInt32( Console.ReadLine() ); Because the task instruction says "...program to take the age of each passenger as input ..." In your code, you use 14, your code don't read input for <age>.
29th Jun 2022, 12:36 AM
Ipang
0
If you mean like this, I tried and work only with lower or equal ages like when I add value 14 to age. I tried with this method to add "else" and doesn't work int age = Convert.ToInt32(Console.ReadLine()); //tu código va aquí if (age <= 19); { Console.WriteLine("Take your kindle"); }
29th Jun 2022, 6:43 AM
Alex
Alex - avatar
0
FIND SOLUTION THANKS FOR HELP. ACTUALLY THE ERROR WAS ALSO THE ( ; ) AFTER IF AND ELSE int age = Convert.ToInt32(Console.ReadLine()); if (age <= 19) Console.WriteLine("Take your kindle"); else Console.WriteLine ("");
29th Jun 2022, 10:05 AM
Alex
Alex - avatar
0
what is the final answer? The full code?
20th Dec 2022, 5:49 PM
Сергій Носатий
Сергій Носатий - avatar