Advertisement
n128

Media

Nov 28th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 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 Media
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Esté programa calcula la nota media de diversos exámenes.");
  14.             Console.WriteLine("Introduzca notas de exámenes hasta que desee. Cuando quiera terminar, introduzca -1" + Environment.NewLine);
  15.  
  16.             int numero_de_notas = 0;
  17.             double suma_de_notas = 0;
  18.             double numero_introducido = 0;
  19.  
  20.             /*
  21.              * Ex:
  22.              *  do {
  23.              *  
  24.              *  } while(edad > 16);
  25.  
  26.              *  El bucle se ejecutará una sola vez. Se compara al final.
  27.              */
  28.  
  29.             numero_introducido = Convert.ToDouble(Console.ReadLine());
  30.  
  31.             do
  32.             {
  33.                 suma_de_notas += numero_introducido;
  34.                 numero_de_notas++;
  35.                 numero_introducido = Convert.ToDouble(Console.ReadLine());
  36.  
  37.             } while (numero_introducido != -1);
  38.  
  39.             /*
  40.             // Repite lo que haya dentro siempre que la condición sea TRUE
  41.             while(numero_introducido != -1)
  42.             {
  43.                 numero_introducido = Convert.ToDouble(Console.ReadLine());
  44.                 if(numero_introducido != -1)
  45.                 {
  46.                 // suma_de_notas = suma_de_notas + Convert.ToDouble(Console.ReadLine());
  47.                 suma_de_notas += numero_introducido;
  48.                 // +1
  49.                 numero_de_notas++;
  50.                 }
  51.            */
  52.  
  53.             double media = suma_de_notas / numero_de_notas;
  54.             Console.WriteLine("La media es " + media);
  55.  
  56.             Console.ReadKey();
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement