我试图自己学习swift,但是我碰到了一堵小墙,我在这里错过了什么?将数据存储在swift中的类数组
https://i.stack.imgur.com/WmZUu.png
import Foundation
class aluno
{
var cpf: String?
var notaP1: Double = 0.0
var notaP2: Double = 0.0
var notaFinalAluno: Double = 0.0
}
var condiçaoLoop = 1
var count = 0
func verificaNota()
{
while condiçaoLoop != 0
{
print("Digite o cpf do aluno")
let cpfAluno = readLine()
print("Digite a nota da P1 do aluno")
let notaP1Aluno = Double(readLine()!)
print("Digite a nota da P2 do aluno")
let notaP2Aluno = Double(readLine()!)
let notaFinalAluno = (notaP1Aluno! + notaP2Aluno!)/2
if notaFinalAluno >= 7
{
print("Aluno aprovado com média: \(notaFinalAluno)")
print("Deseja verificar mais algum aluno? 1 Sim 0 Não")
let resposta = Int(readLine()!)
if resposta == 0
{
condiçaoLoop = 0
}
}
else
{
print("Aluno de final com média: \(notaFinalAluno)")
print("Deseja verificar mais algum aluno? 1 Sim 0 Não")
let resposta = Int(readLine()!)
if resposta == 0
{
condiçaoLoop = 0
}
}
count += 1
}
for i in 1...count
{
var notasAlunos: [aluno] = []
notasAlunos.cpf[i] = cpfAluno
notasAlunos.notaP1[i] = notaP1Aluno!
notasAlunos.notaP2[i] = notaP2Aluno!
notasAlunos.notaFinalAluno[i] = notaFinalAluno
}
}
verificaNota()
什么即时试图做的是从用户那里获取两个档次,计算它的最终得分,然后将数据
出了什么问题?你看到了什么? – Magnas
image没有加载,对不起,我看到这个,当我尝试编译它: nota.swift:52:24:错误:使用未解析的标识符'cpfAluno' notasAlunos.cpf [i] = cpfAluno :53:27:错误:使用未解析的标识符'notaP1Aluno' notasAlunos.notaP1 [i] = notaP1Aluno! Calcular_Nota.swift:51:7:note:你的意思是'notasAlunos'? var notasAlunos:[aluno] = [] 54:27:错误:使用未解析的标识符'notaP2Aluno' notasAlunos.notaP2 [i] = notaP2Aluno! 注意:你的意思是'notasAlunos'? var notasAlunos:[aluno] = [] –