You are on page 1of 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

class operaciones

{
static void Main(string[] args)

Console.Clear();

Console.Title = "Programa de compra de varios productos";


bool CICLO = true;
do

{
Console.Clear();

Console.ForegroundColor = ConsoleColor.Yellow;
string N1 = "UNIVERSIDAD DE SAN PEDRO SULA";
string N2 = "ALUMNA: ROSA ELISA CALDERON CARRASCO";
string N3 = "ASIGNATURA: PROGRAMACION I (2P-2021)";
string N4 = "PROGRAMA DE COMPRAS DE PRODUCTOS";
string N5 = "FECHA DE ENTREGA: 26/06/2021 ";
Console.WriteLine();
Console.WriteLine(DateTime.Now.ToLongDateString());
DateTime hora = DateTime.Now;
Console.WriteLine(string.Format("{0:hhhh:mm}", hora));

for (int X1 = 0; X1 <= Console.WindowWidth - 1; X1++)


{
Console.Write("=");
}
Console.SetCursorPosition((Console.WindowWidth - N1.Length) / 2, 4);
Console.WriteLine(N1);
Console.SetCursorPosition((Console.WindowWidth - N2.Length) / 2, 5);
Console.WriteLine(N2);
Console.SetCursorPosition((Console.WindowWidth - N3.Length) / 2, 6);
Console.WriteLine(N3);
Console.SetCursorPosition((Console.WindowWidth - N4.Length) / 2, 7);
Console.WriteLine(N4);
Console.SetCursorPosition((Console.WindowWidth - N5.Length) / 2, 8);
Console.WriteLine(N5);

for (int X2 = 0; X2 <= Console.WindowWidth - 1; X2++)


{
Console.Write("=");

// OPERACIONES ARITMETICAS CON METODOS MATH


Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine();
// Ingreso de compras de varios productos

Console.WriteLine();

string NPR;
int CantP;
int Total;
int Precio;

Console.WriteLine();
Console.Write(" Ingrese el nombre del producto a comprar....: ");
NPR = Console.ReadLine();
Console.WriteLine();

Console.Write(" Ingrese la cantidad de compra por Und.......: ");


int.TryParse(Console.ReadLine(), out CantP);
Console.WriteLine();
Console.Write(" Ingrese el precio del producto..............: ");
int.TryParse(Console.ReadLine(), out Precio);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" La cantidad a pagar es......................: ");
Console.WriteLine(Total = CantP * Precio);
Console.WriteLine();

Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("¿Desea guardar el registro de compra? (S/N)");
string GUARDAR = Console.ReadLine().ToUpper();
if (GUARDAR == "S")
{
bool EXISTE = File.Exists("./ compras.xls");
if (EXISTE == false)
{
using (StreamWriter PRG = new StreamWriter(" ./compras.xls"))
{
PRG.Write("producto" + "\t" + "cant" + "\t" + "precio" + "\
t" + "totalidad");
PRG.WriteLine();
PRG.Write(NPR + "\t" + CantP + "\t" + Precio + "\t" + Total
+ "\t");
}
}

else
{
using (StreamWriter PRG = File.AppendText("./compras.xls"))
{
PRG.Write(NPR + "\t" + CantP + "\t" + Precio + "\t" + Total
+ "\t");
}
}
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("¿Desea realizar otra Operacion Matematica? (S/N)... ");
Console.ForegroundColor = ConsoleColor.Gray;
string ciclo = Console.ReadLine().ToUpper();
switch (ciclo)
{
case "S": Console.Clear(); break;
case "N": CICLO = false; break;
default: Console.Beep(); Environment.Exit(0); break;
}

} while (CICLO == true);

Console.ReadKey();
}
}

You might also like