Advertisement
dimipan80

Code Abbey. Body Mass Index

Jun 25th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. namespace BodyMassIndex
  2. {
  3.     using System;    
  4.  
  5.     public class BodyMassIndex
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             checked
  10.             {
  11.                 int count = int.Parse(Console.ReadLine());
  12.                 double[,] measures = new double[count, 2];                
  13.                 for (int row = 0; row < count; row++)
  14.                 {
  15.                     string inputLine = Console.ReadLine();
  16.                     char[] separators = new char[] { ' ', ',', ';' };
  17.                     string[] numStr = inputLine.Split(separators, StringSplitOptions.RemoveEmptyEntries);
  18.                     for (int col = 0; col < 2; col++)
  19.                     {
  20.                         measures[row, col] = double.Parse(numStr[col]);
  21.                     }
  22.                 }                
  23.  
  24.                 for (int row = 0; row < measures.GetLength(0); row++)
  25.                 {
  26.                     double result = CalculateBodyMassIndexOfOnePerson(measures[row, 0], measures[row, 1]);
  27.                     PrintResultGrade(result);
  28.                 }
  29.             }
  30.         }
  31.  
  32.         private static void PrintResultGrade(double result)
  33.         {
  34.             checked
  35.             {
  36.                 if (result < 18.5)
  37.                 {
  38.                     Console.Write("under ");
  39.                 }
  40.                 else if (result >= 18.5 && result < 25.0)
  41.                 {
  42.                     Console.Write("normal ");
  43.                 }
  44.                 else if (result >= 25.0 && result < 30.0)
  45.                 {
  46.                     Console.Write("over ");
  47.                 }
  48.                 else if (result >= 30.0)
  49.                 {
  50.                     Console.Write("obese ");
  51.                 }
  52.             }
  53.         }
  54.  
  55.         private static double CalculateBodyMassIndexOfOnePerson(double weight, double height)
  56.         {
  57.             checked
  58.             {
  59.                 double bmi = weight / (height * height);
  60.                 return bmi;
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement