Last active
November 19, 2020 12:21
-
-
Save internetova/41dd980d3f60f4408c879d502426763b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Задание 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