if else文で発生しているエラーを解消したい。
paizaのスキルチェックの問題をやっています。if文ではエラーは発生していないのですが、その下の二つのif elseの行でどちらもエラーが発生しています。条件の部分などが間違っているのでしょうか。お教えいただきたいです。
発生している問題・エラーメッセージ
Main.swift:46:6: error: consecutive statements on a line must be separated by ';' } if else N > 0 && B > 0 && C == 0 { ^ ; Main.swift:46:10: error: expected expression, var, or let in 'if' condition } if else N > 0 && B > 0 && C == 0 { ^ Main.swift:50:6: error: consecutive statements on a line must be separated by ';' } if else N > 0 && B == 0 && C == 0 { ^ ; Main.swift:50:10: error: expected expression, var, or let in 'if' condition } if else N > 0 && B == 0 && C == 0 { ^ Main.swift:46:40: error: closure expression is unused } if else N > 0 && B > 0 && C == 0 { ^ Main.swift:46:40: note: did you mean to use a 'do' statement? } if else N > 0 && B > 0 && C == 0 { ^ do Main.swift:50:41: error: closure expression is unused } if else N > 0 && B == 0 && C == 0 { ^ Main.swift:50:41: note: did you mean to use a 'do' statement? } if else N > 0 && B == 0 && C == 0 { ^ do
該当のソースコード
import Foundation
var str = readLine()!.components(separatedBy:" ")
var num = Int
for i in str {
num.append(Int(i)!)
print(i)
}
var M:Int = num[0] //M = 立候補者
var N:Int = num[1] //N = 有権者
print(str)
var A:Int = 0
var B:Int = 0
var C:Int = 0
var Astr = readLine()!
var Astr2 = readLine()!
var Bstr = readLine()!
var Cstr = readLine()!
var Aspeech = Int(Astr)!
var Aspeech2 = Int(Astr2)!
var Bspeech = Int(Bstr)!
var Cspeech = Int(Cstr)!
var speech:[Int] = []
speech.append(contentsOf: [ Aspeech , Aspeech2 , Bspeech , Cspeech ])
print(speech)
for num in speech {
print(num)
var order = num
if order == 1 {
if N > 0 && B > 0 && C > 0 {
A += 1 + 1 + 1
N -= 1
B -= 1
C -= 1
} if else N > 0 && B > 0 && C == 0 {
A += 1 + 1
N -= 1
B -= 1
} if else N > 0 && B == 0 && C == 0 {
A += 1
N -= 1
}
}
}
### 試したこと とりあえずエラー文をコピペしてGoogle検索して調べてみましたが、どのように解決へと結びつけるのかわからない状態です。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/01 10:50