Last active
November 25, 2020 14:02
-
-
Save karabanovbs/1186b4319432db99484d6802459a5e1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import 'dart:convert'; | |
import 'dart:io'; | |
// 2.4 Управляющие конструкции | |
// Написать программу, которая слушает ввод в консоли, складывает вводимые пользователем числа. | |
// Если пользователь ввел stop, завершить приложение. | |
// Если пользователь вводит некорректные данные - прервать текущую итерацию, начать заново. | |
void main(List<String> arguments) { | |
var sum = 0.0; | |
while (true) { | |
var inVal = stdin.readLineSync(encoding: Encoding.getByName('utf-8')); | |
var currentValue = double.tryParse(inVal); | |
if (inVal == 'stop') { | |
break; | |
} else if (currentValue != null) { | |
sum += currentValue; | |
} else { | |
continue; | |
} | |
} | |
print(sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment