Jump to content

Need Help: Very simple C# code

- - - - -

  • Please log in to reply
2 replies to this topic

#1
hayleigh

hayleigh

    Newbie

  • Members
  • Pip
  • 2 posts
Well, I'm in my first month of learning C#, and never had to use this kind of forums.
I have my coursework to hand in on Monday and I can't understand what's wrong with my code!

Console.WriteLine("Insert pupil's height (in cm):");

            int height = int.Parse(Console.ReadLine());

            Console.WriteLine("Insert pupil's age:");

            int age = int.Parse(Console.ReadLine());


            while(!(age>8) && !(height>170))

            {

                int a, b, ageA, ageB, heightA, heightB = 0;


                if(age>8 || height>150)

                {

                    a++;

                    ageA+=age;

                    heightA+=height;

                }


                else

                {

                    b++;

                    ageB+=age;

                    heightB+=height;

                }


                Console.WriteLine("Insert pupil's height (in cm):");

                height=int.Parse(Console.ReadLine());

                Console.WriteLine("Insert pupil's age:");

                age=int.Parse(Console.ReadLine());


            }


            


            Console.WriteLine("Group A's average age is "+ageA/a+", and average height is "+heightA/a);

            Console.WriteLine("Group B's average age is "+ageB/b+", and average height is "+heightB/b);


Thanks a lot!
Hayleigh.

#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript
What kind of error do you have?

#3
hayleigh

hayleigh

    Newbie

  • Members
  • Pip
  • 2 posts
Something with the variables, but it's alright - I found my error, thanks anyway!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users