Skip to content

Instantly share code, notes, and snippets.

@internetova
Last active November 19, 2020 12:21
Show Gist options
  • Save internetova/41dd980d3f60f4408c879d502426763b to your computer and use it in GitHub Desktop.
Save internetova/41dd980d3f60f4408c879d502426763b to your computer and use it in GitHub Desktop.
// Задание 3
// Написать программу, которая слушает ввод в консоли, складывает вводимые пользователем числа.
// Если пользователь ввел stop, завершить приложение. Если пользователь вводит некорректные
// данные - прервать текущую итерацию, начать заново.
import 'dart:io';
void main() {
var total = 0;
while (true) {
stdout.write('\x1b[37m Введите целое число или stop чтобы закончить:\n');
final input = stdin.readLineSync();
if (input == 'stop') {
print(total);
break;
} else {
final inputCheck = int.tryParse(input);
if (inputCheck != null) {
total += inputCheck;
} else {
total = 0;
print('\x1b[31m На колу мочало, начинай сначала \u{1F608}\u{1F608}\u{1F608} \x1b[37m');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment