Jump to content

C# nonsense

stefanmz
Go to solution Solved by stefanmz,

Nevermind I am an idiot it's working correctly I was pointing to the whole array the exception was a culture issue with the decimal , or . moderators you can delete this post

Ok can you help me,because I am writing a homework and why,just why,tell me does the string split here split the string by sentences and not words???!!! It's supposed to split it in words. I literally wrote a program that is written in the same way with the string split going into an array and it works,it splits by words but it doesn't here! Why???? Sorry for the blurry image  but this Data[1] is supposed to be the gender of the Person not the entire freaking Person!! WTF???

using System;

namespace Domashna
{
    class Person
    {
        public string Name { get; set; }
        public string Gender { get; set; }
        public int Age { get; set; }
        public double Height { get; set; }
        public double Weight { get; set; }
        public double Activity { get; set; }
        public  double CaloricBalance { get { return 66.47 + (13.75 * Weight) + (5 * Height) - (6.76 * Age); } set { } }
        public Person(string name,string gender,int age,double height,double weight,double activity)
        {
            Name = name;
            Gender = gender;
            Age = age;
            Height = height;
            Weight = weight;
            Activity = activity;

       
        }
    }
    class Basic006
    {
        
        static void Main(string[] args)
        {
            Console.WriteLine("Enter number of people:");
            bool success = int.TryParse(Console.ReadLine(), out int N);
            if (success == false) {Console.WriteLine("Error,invalid number. Write a whole number(int). Press any key for more info...");
                                   Console.ReadKey();
                                   Console.WriteLine("int is integer:-2,147,483,648 to 2,147,483,647");}
            else
            {
                Console.WriteLine("Write people in following order:Name,Gender,Age,Height,Weight,Coefficient of Activity");
                Person[] people = new Person[N];
                for (int i = 0; i < N; i++)
                {
                    
                    Console.WriteLine($"Person{i}:");
                    string s = Console.ReadLine();
                    string[] Data = s.Split(',');
                    people[i] = new Person(Data[0], Data[1], int.Parse(Data[2]), double.Parse(Data[3]), double.Parse(Data[4]), double.Parse(Data[5]));
                }
              
            }
        }
        private void Print(Person[]people)
        {
            for(int i=0;i<people.Length;i++)
            {
                Console.WriteLine($"{people[i].Name}-{people[i].Age}-Caloric balance:{people[i].CaloricBalance}");
            }
        }
    }
}

image.thumb.png.f94b485b224eb0865bcb1200728f33ce.png

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Nevermind I am an idiot it's working correctly I was pointing to the whole array the exception was a culture issue with the decimal , or . moderators you can delete this post

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×