상점에서 아이템 구매 3번(19.09.23)
Console(콘솔)/실습 2019. 9. 23. 14:08
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Syntax05
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("[Step3]");
Console.WriteLine("반복해서 구매 할수 있도록 해주세요.");
Console.WriteLine("금화가 부족하여 더이상 구매 할수 없는 경우");
Console.WriteLine("\"금화가 부족합니다.\"" + "라고 출력 해주세요.");
int str1 = 0;
int max = 5000;
max = max - str1;
for (int g= 0; g < max-str1;)
{
max = max - str1;
e:
f:
Console.WriteLine("상점에서 구입 하고자 하는 아이템을 입력해주세요.");
Console.WriteLine("상품목록");
Console.WriteLine("---------------------------------");
Console.WriteLine("장검 : 800");
Console.WriteLine("단검 : 550");
Console.WriteLine("활 : 760");
Console.WriteLine("도끼 : 810");
Console.WriteLine("---------------------------------");
Console.WriteLine("남은 금화: " + max);
Console.Write("입력 : ");
string str = Console.ReadLine();
Console.WriteLine("입력: " + str);
if (str == "장검")
{
str1 = 800;
}
else if (str == "단검")
{
str1 = 550;
}
else if (str == "활")
{
str1 = 760;
}
else if (str == "도끼")
{
str1 = 810;
}
else
{
Console.WriteLine("출력: 해당상품(\"" + str + "\")는(은) 없습니다.");
goto e;
}
if(g<max -str1)
{
Console.WriteLine(str + "을 구매 했습니다.");
}
if (g > max - str1)
{
Console.WriteLine(str+"을(를) 구매하지 못햇습니다.");
Console.WriteLine("\"금화가 부족합니다.\"");
goto f;
}
}
}
}
}
|
'Console(콘솔) > 실습' 카테고리의 다른 글
상품 구매 및 판매(19.09.23) (0) | 2019.09.23 |
---|---|
상점에서 구매 후 구매 목록 작성(19.09.23) (0) | 2019.09.23 |
상점에서 아이템 구매 2번(19.09.23) (0) | 2019.09.23 |
상점에서 아이템 구매 1번(19.09.23) (0) | 2019.09.23 |
if else를 이용한 줄넘기 입력 실패시 되돌리기(19.09.20) (0) | 2019.09.20 |