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

30th May 2021, 3:38 AM
Sachiikoo
Sachiikoo - avatar
9 odpowiedzi
+ 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
30th May 2021, 3:47 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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
30th May 2021, 5:03 AM
Simba
Simba - avatar
+ 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 +" "); } } } } }
30th May 2021, 3:48 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Simba Thanks for your help.
30th May 2021, 6:49 AM
Sachiikoo
Sachiikoo - avatar
30th May 2021, 3:56 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
How do I po replace the line of numbers in the output . If what I want is to display only the age Category?☺️
30th May 2021, 4:47 AM
Sachiikoo
Sachiikoo - avatar
+ 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 &&
30th May 2021, 5:53 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Sachiikoo you don't need the for loop and the if statement can be changed to else if or the switch statement
30th May 2021, 6:25 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
A.S thanks for your further Explanation I got it..
30th May 2021, 6:50 AM
Sachiikoo
Sachiikoo - avatar