C#-Assignment 1

Jisu Lee·2022년 11월 3일
0

C# 코드 모음집

목록 보기
1/5
post-thumbnail

velog를 시작해보았습니다. 지금까지 만들어 놓은 작지만 소듕한 코드들을 한번 끄적거려 보겠습니다.

다음은 S308 - Business Application Development C#을 배우는 수업에서 제출한 첫 번째 과제 (Generating a Health Report Card)입니다.

class MainClass {
  public static void Main (string[] args) {
    
    //Users input their information in the system about their last name, first name, year they were born, their weight, and their waistline
    Console.WriteLine("Hi, please enter information to calculate your health status. What is your last name?");
		string strLast_Name = Console.ReadLine();
    Console.WriteLine("What is your first name?");
		string strFirst_Name = Console.ReadLine();
    Console.WriteLine("When were you born (in year)?");
		string strYear_Born = Console.ReadLine();
    Console.WriteLine("What's your weight (in kg)?");
		string strWeight = Console.ReadLine();
    Console.WriteLine("Please tell me your waistline (in cm).");
		string strWaistline = Console.ReadLine();
    
    //Converts string to double for calculation
    double DYear_Born = Convert.ToDouble(strYear_Born);
		double DWeight = Convert.ToDouble(strWeight);
    double DWaistline = Convert.ToDouble(strWaistline);

    //Calculates age, bone density, fat percentage
    double DAge = 2022-DYear_Born;
    double DBone_Density = (DWeight-DAge)*0.2;
    double DFat_Percentage = Math.Round(((DWaistline*0.74-DWeight*0.08-40)/DWeight*100),2);

    //Displays the output to the users 
    Console.WriteLine("=========================");
    Console.WriteLine("Name: " + strFirst_Name + " " + strLast_Name);
    Console.WriteLine("Your age: " + DAge);
    Console.WriteLine("Your weight: " + DWeight +"kg");
    Console.WriteLine("Your waistline: " + DWaistline +"cm");
    Console.WriteLine("Bone Density: " + DBone_Density);
    Console.WriteLine("Body Fat Percentage: " + DFat_Percentage +"%");


  }
}

코드를 돌리면 다음과 같은 결과값이 도출됩니다.

Replit을 이용해 만들어보았습니다.

0개의 댓글