3일차 당신이 입력한 숫자의 합은 ... 입니다.

Console Programming/C# Console 2019. 9. 20. 10:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax05
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("*** 0보다 크고 100보다 작은 숫자 두개를 입력하고 출력 하기 ***");
            Console.Write("첫번째 숫자를 입력 해주세요.");
            string input1 = Console.ReadLine();
            Console.Write("두번째 숫자를 입력해주세요.");
            string input2 = Console.ReadLine();
 
            Console.WriteLine($"당신이 입력한 숫자는 {input1}, {input2} 입니다.");
 
            int ConvertedVal1 = Int32.Parse(input1);
            int ConvertedVal2 = Int32.Parse(input2);
 
            Console.WriteLine($"당신이 입력한 숫자의 합은 {ConvertedVal1+ConvertedVal2} 입니다.");
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

19 라인은 입력받은 숫자를 단지 보여주기 때문에 형 변환이 필요 없다.

그러나

24라인은 그 값을 더해야 하므로, 입력받은 문자열형 숫자값을 int32형 숫자로 변환하고, 그 값을 출력한다.

 

: