'Terminal does not give the right answer
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);
}
Solution 1:[1]
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);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Szymon Kowali?ski |
