mercredi 1 décembre 2021

How can I define a boolean value under an if statement

import "dart:io";
import "dart:math";


String promptStudent(){
print("are you a student?");
String Student = stdin.readLineSync()!;
return Student;
}

String promptSmart(){
print("2+2=?");
String Smart = stdin.readLineSync()!;
return Smart;
}



void main() {
  String student = promptStudent();
  if(student == "yes"){
  bool isStudent = true;
  } else() {
  bool isStudent = false;
  };
  String smart = promptSmart();
  if(smart == "4"){
  bool isSmart = true;
  } else() {
  bool isSmart = false;
  };

  if(isSmart && isStudent) {
  print("he is a smart student");
  }
  else if(isSmart && !isStudent) {
  print("he is smart but not a student");
  }
  else if(!isSmart && isStudent) {
  print("he isnt smart but a student");
  }
  else if(!isSmart && !isStudent) {
  print("he is not smart and not a student");
  };

}

I wanted to set a boolean by user input (if answer to 2+2 is 4 he is smart etc.), but I get issues like the following:

main.dart:42:24: Error: Getter not found: 'isStudent'. else if(!isSmart && !isStudent) {

What is wrong here? How can I fix it?

Aucun commentaire:

Enregistrer un commentaire