Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
use std::io::{self, Write}; fn main() { let mut input = String::new(); let mut integer = 0; let mut total = 0; while integer >= 0 { print!("Enter a positive integer (to exit, enter a negative number): "); io::stdout().flush().expect("can't flush std out."); match io::stdin().read_line(&mut input) { Ok(_) => {} Err(err) => eprintln!("error reading from standard input. ERR: {}", err), } match input.strip_suffix("\n") { Some(str) => input = str.to_string(), None => { println!("You entered nothing."); continue; } } match input.parse::
() { Ok(value) => { if value < 0 { break; } integer += 1; total += value; } Err(err) => eprintln!( "invalid input {input}. must be a postive or negative integer. ERR: {err}" ), } input.clear(); } if integer > 0{ println!("The total numbers of positive integers entered is {integer}"); } println!("The sum of all positive integer(s) is {total}."); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)