0
Can someone help me to fixed this code.
I need an output with A single line containing the appropriate age category Out sample: Teenager https://code.sololearn.com/cXxdWSGznI3L/?ref=app
9 Réponses
+ 1
You if condition is wrong becz u using class name as variable and your age variable is un-initilized. And in all if conditions u written
If(0<=age<=45) which is wrong here u need to write logical operator || or && . and also closing brackets are missing
+ 5
It's not necessary to use for loop here.
You need to change the age category in 2nd & 3rd statement(also check the range)
https://code.sololearn.com/czzUGRstG4T7/?ref=app
+ 2
try now in if condition you have to write input which you taking as a input instead of age becz age is you class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace age
{
class Program
{
static void Main(string[] args)
{
int input =
Convert.ToInt32(Console.ReadLine());
if (0<=input && input<=12)
Console.WriteLine("Child");
if (13<=input && input<=17)
Console.WriteLine("Adult");
if (18<=input && input<=59)
Console.WriteLine("Teenager");
if (59<=input && input<=99)
Console.WriteLine("Senior Citizen");
for (int i=0;i< input; i++)
{
if(i!= 0 && i % 1== 0)
{
Console.WriteLine(i);
}
else
{
Console.Write( i +" ");
}
}
}
}
}
+ 2
Simba Thanks for your help.
+ 1
How do I po replace the line of numbers in the output . If what I want is to display only the age Category?☺️
+ 1
Sachiikoo if u want to display age category then in condition you have to use (&& ) or (|| ) operators as in my answer i have already mentioned .
If(0<=input && input<=58) this will work of both condition will be true otherwise it will not execute statement which will be written inside if body same or(|| ) operator this will execute if your one conditions will be true . Here you need logical &&
+ 1
Sachiikoo you don't need the for loop and the if statement can be changed to else if or the switch statement
+ 1
A.S thanks for your further Explanation I got it..