Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7. int negCount = 0; // Negative numbers count
  8. int number; // Your input
  9. int numCount = 0; // Input count
  10. int sumOfNegetives = 0; // Do you want the sum(?)
  11.  
  12.  
  13. while(numCount < 5) // running 20 times
  14. {
  15. Console.Write("Enter a number: ");
  16. number = int.Parse(Console.ReadLine()); // receiving an input
  17.  
  18. if(number < 0)
  19. {
  20. sumOfNegetives = number + sumOfNegetives; // Summing the negative numbers
  21. negCount++; // counts negative numbers
  22. }
  23.  
  24. numCount++; // counts how many inputs you received
  25.  
  26. }
  27. Console.WriteLine("there are: " + negCount + " negative numbers, " + "and their sum is:" + sumOfNegetives ); // print
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement