区块报价
我想做一个计算器来计算科目的一般要点。对于exm,每一个正确的数学问题都给出8分,所以25个问题和5个错误的答案将给出25-5=20*8=160。然后继续计算其他科目(历史,地理.)在结束时告诉我最后的要点。在终点站,它问了我一个错误的问题,然后并没有显示出一般的观点。我该怎么办?
void main() {
String? Subject;
int General;
String? Math;
String? History;
String? Geography;
String? Spanish;
String? English;
int AllQuestions;
int Wrong;
print("Let's calculate your points");
print("Choose the subject");
Subject = stdin.readLineSync();
print("Enter the number of questions");
AllQuestions = int.parse(stdin.readLineSync()!);
print("Enter the number of wrong questions");
Wrong = int.parse(stdin.readLineSync()!);
if (Subject == Math) {
General = (AllQuestions - Wrong)*8;
print(General);
}
if (Subject == History) {
General = (AllQuestions - Wrong)*4;
print(General);
}
if (Subject == Geography) {
General = (AllQuestions - Wrong)*8;
print(General);
}
if (Subject == Snapish) {
General = (AllQuestions - Wrong)*4;
print(General);
}
if (Subject == English) {
General = (AllQuestions - Wrong)*4;
print(General);
}发布于 2022-02-26 20:20:12
因为您不使用String的值来初始化变量。示例:
String? Math;应:
String? Math = "Math";发布于 2022-02-26 21:14:36
我相信你想要这样的东西:
void main() {
String? Subject;
int General;
int AllQuestions;
int Wrong;
print("Let's calculate your points");
print("Choose the subject");
Subject = stdin.readLineSync();
print("Enter the number of questions");
AllQuestions = int.parse(stdin.readLineSync()!);
print("Enter the number of wrong questions");
Wrong = int.parse(stdin.readLineSync()!);
if (Subject == "Math") {
General = (AllQuestions - Wrong)*8;
print(General);
}
if (Subject == "History") {
General = (AllQuestions - Wrong)*4;
print(General);
}
if (Subject == "Geography") {
General = (AllQuestions - Wrong)*8;
print(General);
}
if (Subject == "Spanish") {
General = (AllQuestions - Wrong)*4;
print(General);
}
if (Subject == "English") {
General = (AllQuestions - Wrong)*4;
print(General);
}
}https://stackoverflow.com/questions/71276911
复制相似问题