質問編集履歴

4

データが5個の場合、Yearが0から始まる場合について、if文とswitch文を使わない書き方を考えました。

2018/02/28 03:00

投稿

mocchisu
mocchisu

スコア7

test CHANGED
File without changes
test CHANGED
@@ -137,3 +137,25 @@
137
137
 
138
138
 
139
139
  ```
140
+
141
+
142
+
143
+ Yearが0から始まる場合について、if文とswitch文を使わない書き方を考えました。
144
+
145
+
146
+
147
+ ```Swift
148
+
149
+ var Year = 1
150
+
151
+ var Weight = 10
152
+
153
+
154
+
155
+ let WeightAverage = [1, 9, 10, 11, 12, 13]
156
+
157
+ let result = WeightAverage[Year]-Weight
158
+
159
+ print("(result)")
160
+
161
+ ```

3

データが5個の場合、配列を使った書き方を考えてみました。

2018/02/28 03:00

投稿

mocchisu
mocchisu

スコア7

test CHANGED
File without changes
test CHANGED
@@ -87,3 +87,53 @@
87
87
  }
88
88
 
89
89
  ```
90
+
91
+
92
+
93
+ データが5個の場合、配列を使った書き方を考えてみました。
94
+
95
+ ```Swift
96
+
97
+ var Year = 1
98
+
99
+ var Weight = 10
100
+
101
+
102
+
103
+ let WeightAverage = [9, 10, 11, 12, 13]
104
+
105
+ if Year == 1 {
106
+
107
+ let result = WeightAverage[0] - Weight
108
+
109
+ print("(result)")
110
+
111
+ } else if Year == 2{
112
+
113
+ let result = WeightAverage[1] - Weight
114
+
115
+ print("(result)")
116
+
117
+ } else if Year == 3{
118
+
119
+ let result = WeightAverage[2] - Weight
120
+
121
+ print("(result)")
122
+
123
+ } else if Year == 4{
124
+
125
+ let result = WeightAverage[3] - Weight
126
+
127
+ print("(result)")
128
+
129
+ } else {
130
+
131
+ let result = WeightAverage[4] - Weight
132
+
133
+ print("(result)")
134
+
135
+ }
136
+
137
+
138
+
139
+ ```

2

データが5個のばあいの追記を行いました。

2018/02/28 01:55

投稿

mocchisu
mocchisu

スコア7

test CHANGED
File without changes
test CHANGED
@@ -35,3 +35,55 @@
35
35
 
36
36
 
37
37
  データの内容は、「年齢月齢とそれに対応する体重の全国平均値」のような物です。
38
+
39
+
40
+
41
+
42
+
43
+ データが5個の場合を考えました。
44
+
45
+
46
+
47
+ ```Swift
48
+
49
+ var Year = 1
50
+
51
+ var Weight = 10
52
+
53
+
54
+
55
+ switch Year {
56
+
57
+ case 1:
58
+
59
+ let result = 9 - Weight
60
+
61
+ print("(result)")
62
+
63
+ case 2:
64
+
65
+ let result = 10 - Weight
66
+
67
+ print("(result)")
68
+
69
+ case 3:
70
+
71
+ let result = 11 - Weight
72
+
73
+ print("(result)")
74
+
75
+ case 4:
76
+
77
+ let result = 12 - Weight
78
+
79
+ print("(result)")
80
+
81
+ default:
82
+
83
+ let result = 13 - Weight
84
+
85
+ print("(result)")
86
+
87
+ }
88
+
89
+ ```

1

2018/02/28 01:07

投稿

mocchisu
mocchisu

スコア7

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  上の②の部分でどのような方法を使うのが良いのかがわからず、困っています。
26
26
 
27
- データの数が300個くらいあるのですが、全てをコード内で記述して代入する必要があるのか、それとも、何か外部のソフトの様なものと繋げて比較する方法を使った方が良いのでしょうか。
27
+ データの数が600個くらいあるのですが、全てをコード内で記述して代入する必要があるのか、それとも、何か外部のソフトの様なものと繋げて比較する方法を使った方が良いのでしょうか。
28
28
 
29
29
 
30
30