Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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(" "); } } } }
12 Respostas
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
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");
}
}
}
}
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.
0
I tried without the else block and doesn't work
0
Pass me the task Description, I need to read it ...
0
Is in Spanish i write it as answer on top
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.
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
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>.
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");
}
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 ("");
0
what is the final answer? The full code?