Blockquote
I want to make a calculator which calculate the general point of subjects. For exm, every right question of Math gives 8 points, so 25 questions and 5 wrong answers will give 25-5=20*8=160. And then continue to count other subjects (History, Geography...) to give me at the end the total point. In terminal it asks me till the wrong question and then does not show the general point. What should I do?
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);
}
CodePudding user response:
Because you intialized your variables with no values for the Strings. Example:
String? Math;
should be:
String? Math = "Math";
CodePudding user response:
I believe you want something like this:
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);
}
}