using System;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace Calculo_cilindro_voz_consola_02_cs
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Cálculo litros de un depósito - By Meta. Electrónica PIC";
Console.SetWindowSize(55, 16);
#region Variables.
const double Pi = 3.14;
float PI = Convert.ToSingle(Pi);
float radio, altura, volumen, litros, nivelAgua, resultadoPorcentaje,
resultadoLitros, volumenLitros, mitadBarra, cantidadTubosLitros,
totalLitros;
float cantidadTubos;
#endregion
do
{
try
{
using (SpeechSynthesizer altavoz = new SpeechSynthesizer())
{
#region Introducción de datos en la pantalla.
altavoz.SetOutputToDefaultAudioDevice();
altavoz.Rate = -2;
altavoz.Volume = 100;
Console.Clear();
Console.CursorVisible = true;
Console.Write("Introduce el radio en m.: ");
altavoz.Speak("Introduce el radio en metros.");
radio = float.Parse(Console.ReadLine());
Console.Write("Introduce la altura del tubo en m.: ");
altavoz.Speak("Introduce la altura del tubo en metros.");
altura = float.Parse(Console.ReadLine());
Console.Write("Introduce altura del agua. Máximo es de {0} m.: ", altura);
altavoz.Speak("Introduce altura del agua. Máximo es de " + altura + "metros.");
nivelAgua = float.Parse(Console.ReadLine());
Console.Write("Introduce cantidad de tubos: ");
altavoz.Speak("Introduce cantidad de tubos.");
cantidadTubos = int.Parse(Console.ReadLine());
#endregion
#region Cálculos.
volumen = PI * (radio * radio) * altura;
litros = volumen * 1000;
resultadoPorcentaje = nivelAgua * (100 / altura);
volumenLitros = PI * (radio * radio) * nivelAgua;
resultadoLitros = volumenLitros * 1000;
cantidadTubosLitros = cantidadTubos * resultadoLitros;
totalLitros = litros * cantidadTubos;
#endregion
#region Dibujado barra de progreso.
Console.SetCursorPosition(0, 4);
Console.WriteLine();
Console.WriteLine("0 % 50 % 100 %");
Console.WriteLine("┌────────────────────────┬───────────────────────┐");
mitadBarra = resultadoPorcentaje / 2;
if (resultadoPorcentaje <= 15)
{
Console.ForegroundColor = ConsoleColor.Red;
}
else if (resultadoPorcentaje <= 40)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else if (resultadoPorcentaje <= 100)
{
Console.ForegroundColor = ConsoleColor.Green;
}
if (mitadBarra > 50)
{
mitadBarra = 50;
}
Console.SetCursorPosition(0, 7);
for (int i = 1; i <= mitadBarra; i++)
{
Console.Write("█");
}
Console.ForegroundColor = ConsoleColor.Gray;
if (resultadoPorcentaje > 100)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("#");
Console.ForegroundColor = ConsoleColor.Gray;
}
#endregion
#region Mostrar textos en pantalla.
Console.CursorVisible = false;
Console.SetCursorPosition(0, 9);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\nPorcentaje: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(resultadoPorcentaje.ToString("N2") + " %.");
altavoz.Speak("Cantidad de agua que hay en el depósito es de " +
resultadoPorcentaje + "%.");
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\nLitros de agua: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(resultadoLitros.ToString("N2"));
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" / " + litros.ToString("N2") + " L. total de un tubo.");
altavoz.Speak("Cantidad de litros de agua en un tubo de " +
resultadoLitros.ToString("N2") + "de " +
litros.ToString("N2") + " litros total de un tubo.");
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\nCantidad de Litros total por " + cantidadTubos + " tubos: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(cantidadTubosLitros.ToString("N2"));
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" / " + totalLitros.ToString("N2") + " L.");
altavoz.Speak("Cantidad de litros en total por " + cantidadTubos.ToString("N2") +
" tubos: " + cantidadTubosLitros.ToString("N2") +
" de " + totalLitros.ToString("N2") + " litros.");
#endregion
}
}
catch (FormatException)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Red;
Console.Clear();
Console.SetCursorPosition(8, 5);
Console.Write(@"La cadena de entrada no tiene el
formato correcto.
Solo debes introducir números y comas.");
Console.CursorVisible = false;
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.ReadKey();
} while (true);
}
}
}