Total points isnt shown in terminal

Viewed 30
import 'dart:io';

void main() {
  String? Subject;
  int Total = 0;
  String? Math = "Math";
  String? History = "History";
  String? Geography = "Geography";
  String? Azerbaijani = "Azerbaijani";
  String? English = "English";
  int AllQuestions;
  int Wrong;
  print("Let's calculate your balls");

  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) {
    Total = Total + (AllQuestions - Wrong) * 8;
    print(Total);
  };

  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 == History) {
    Total = Total + ((AllQuestions - Wrong) * 4);
    print(Total);
  } ;

  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 == Geography) {
    Total = Total + (AllQuestions - Wrong) * 8;
    print(Total);
  } ;

  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 == Azerbaijani) {
    Total = Total + (AllQuestions - Wrong) * 4;
    print(Total);
  };
  
  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 == English) {
    Total = Total + ((AllQuestions - Wrong) * 4);
    print(Total);
  };
  print("Congrats!");
}
With this one I count the points of each subject. For exm, if I got out of 25 questions only 5 wrong answer, it will be 25-5= 20*8=160

And terminal looks like: Choose the subject: Math; Enter the number of question: 25; Enter the number of wrong questions: 5, Total 160. It works, but then I tried to short this code.

import 'dart:io';

void main() {
  String? Subject;
  int Total = 0;
  String? Math ;
  String? History ;
  String? Geography;
  String? Azerbaijani;
  String? English;
  int AllQuestions = 0;
  int Wrong = 0;
  int Meaning = 0;
  inputsD(Subject, AllQuestions, Wrong,Total);

  if (Subject == "Math") {
    inputsName(Subject, AllQuestions, Wrong, Total, 8);
  } 
  ;
inputsD(Subject, AllQuestions, Wrong,Total);
  if (Subject == "History") {
     inputsName(Subject, AllQuestions, Wrong, Total, 4);
  } 
  ;
inputsD(Subject, AllQuestions, Wrong,Total);
  if (Subject == "Geography") {
    inputsName(Subject, AllQuestions, Wrong, Total, 8);
  } 
  ;
inputsD(Subject, AllQuestions, Wrong,Total);
  if (Subject == "Azerbaijani") {
     inputsName(Subject, AllQuestions, Wrong, Total, 4);
  } 
  ;
inputsD(Subject, AllQuestions, Wrong,Total);
  if (Subject == "English") {
     inputsName(Subject, AllQuestions, Wrong, Total, 4);
  } 
  ;
}

void inputsName(Subject, AllQuestions, Wrong, Total, Meaning) {
  Total = Total + ((AllQuestions - Wrong) * Meaning());
    print(Total);
}
void inputsD(Subject, AllQuestions, Wrong, Total){
  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()!);}

It does not show total point of each subject. What is wrong and how I can fix it? It just asks about subject, al questions and wrong questions, but doesnt show the total point.

0 Answers
Related