Advertisement
Guest User

C# Osumalaskuri

a guest
Dec 10th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp20
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. bool[] osumat = new bool[5];
  14.  
  15. kysyOsumat(osumat);
  16. }
  17.  
  18. static void kysyOsumat(bool [] pOsumat)
  19. {
  20. for (int i =0; i < pOsumat.Length; i++)
  21. {
  22. Console.Write("Osuiko laukaus " + (i + 1) + " (1=osui, 0=ohi) :");
  23. string syote = Console.ReadLine();
  24. int syoteInt = Convert.ToInt32(syote);
  25.  
  26. if (syoteInt == 1)
  27. {
  28. pOsumat[i] = true;
  29. }
  30. else
  31. {
  32. pOsumat[i] = false;
  33. }
  34. }
  35. }
  36.  
  37.  
  38. static void TulostaOsumat(bool[] pOsumat)
  39. {
  40. int osumienLukumaara = 0;
  41.  
  42. for (int i = 0; i < pOsumat.Length; i++)
  43. {
  44. if (pOsumat[i])
  45. {
  46. osumienLukumaara++;
  47. }
  48. }
  49.  
  50. Console.WriteLine("Osumien lukumäärä on " + osumienLukumaara +
  51. " ja huteja tuli " + (pOsumat.Length - osumienLukumaara));
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement