首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >终端没有给出正确的答案。

终端没有给出正确的答案。
EN

Stack Overflow用户
提问于 2022-02-26 13:05:55
回答 2查看 34关注 0票数 0

区块报价

我想做一个计算器来计算科目的一般要点。对于exm,每一个正确的数学问题都给出8分,所以25个问题和5个错误的答案将给出25-5=20*8=160。然后继续计算其他科目(历史,地理.)在结束时告诉我最后的要点。在终点站,它问了我一个错误的问题,然后并没有显示出一般的观点。我该怎么办?

代码语言:javascript
复制
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);
  }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-02-26 20:20:12

因为您不使用String的值来初始化变量。示例:

代码语言:javascript
复制
String? Math;

应:

代码语言:javascript
复制
String? Math = "Math";
票数 0
EN

Stack Overflow用户

发布于 2022-02-26 21:14:36

我相信你想要这样的东西:

代码语言:javascript
复制
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);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71276911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档