ArmandoCircuitos
Inicio
Electronica
Programacion
Resultado
Codigo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Suministro_Bateria_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } double Ib, Ic; int a = 0; int b = 0; double tiempo, residuo; double[] multiplos = { 0.000000001, 0.000001, 0.001, 1 }; string cadena; private void Form1_Load(object sender, EventArgs e) { cmbBateria.SelectedIndex = 2; cmbCarga.SelectedIndex = 2; } private void calcular() { Ib = Ib * multiplos[a]; Ic = Ic * multiplos[b]; tiempo = Ib / Ic; if (tiempo >= 8640) { tiempo = tiempo / 8640; residuo = tiempo % 1; cadena = Math.Floor(tiempo) + " AƱos y "; cadena += Math.Round((residuo * 12),0) + " meses"; } else { if (tiempo >= 720) { tiempo = tiempo / 720; residuo = tiempo % 1; cadena = Math.Floor(tiempo) + " Meses y "; cadena += Math.Round((residuo * 30),0) + " dias"; } else { if (tiempo >= 24) { tiempo = tiempo / 24; residuo = tiempo % 1; cadena = Math.Floor(tiempo) + " Dias y "; cadena += Math.Round((residuo * 24),0) + " Horas"; } else { residuo = tiempo % 1; cadena = Math.Floor(tiempo) + " Horas y "; cadena += Math.Round((residuo * 60),0) + " Minutos"; } } } lblTiempo.Text = cadena; lblBateria.Text = txtBateria.Text + cmbBateria.Text + "h"; lblCarga.Text = txtCarga.Text + cmbCarga.Text; } private void cmbBateria_SelectedIndexChanged(object sender, EventArgs e) { a = cmbBateria.SelectedIndex; } private void cmbCarga_SelectedIndexChanged(object sender, EventArgs e) { b = cmbCarga.SelectedIndex; } private void button1_Click(object sender, EventArgs e) { Ib = Convert.ToDouble(txtBateria.Text); Ic = Convert.ToDouble(txtCarga.Text); calcular(); lblSalida.Text = lblTiempo.Text; } } }
Descarga del archivo
Descargar archivo