Reputation: 61
Output display user input integer, instead of Even or Odd
import 'dart:io';
void main() {
print('Enter your number: ');
int n = int.parse(stdin.readLineSync()!);
var result = n % 2 == 0 ? "Even" : "Odd";
print('Your number is : $result');
}
Upvotes: 6
Views: 5488
Reputation: 1062
The problem is that you need to change the program from running inside debug console to terminal. To do that open your VSCode settings, and search for dart.cliConsole and change it from Debug Console to terminal.
Before that, make sure you have the flutter extension installed, otherwise you won't see the cli console setting. Hope this helps!
Upvotes: 0
Reputation: 31219
The problem is that your program is running inside the "Debug Console" in VS Code. The following explanation can be found in the Dart settings in VS Code:
The Debug Console has more functionality because the process is controlled by the debug adapter, but is unable to accept input from the user via stdin.
You can change this by going into File -> Preferences -> Settings. Here you go into Extensions -> Dart & Flutter. If you scroll down you can find "Dart: Cli Console". You can also just search for "Dart Cli console":
Instead of "debugConsole" set this to "terminal". Try start your program again and it should now be running inside the "Terminal" tab instead and you should be able to interact with your program and provide data to it though keyboard inputs.
Upvotes: 12