Write a Program that asks the user for the time that he clocked into work and then for the time he clocked out.
Display, in three labels, the total number of seconds worked, and the total number of minutes worked, and the total number of hours worked.
Display, in three labels, the total number of seconds worked, and the total number of minutes worked, and the total number of hours worked.
Solution:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Question1
{
public partial class Form1 : Form
{
int val1, val2, t,min1,min2;
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
val1 = Convert.ToInt32(textBox1.Text);
val2 = Convert.ToInt32(textBox4.Text);
min1 = Convert.ToInt32(textBox2.Text);
min2 = Convert.ToInt32(textBox5.Text);
if (comboBox1.Text == "pm" && comboBox2.Text == "pm")
{
val1 = val1 + 12;
val2 = val2 + 12;
if (val2 > val1)
{
int res = val2 - val1;
Hours.Text = Convert.ToString(res);
}
if (val2 < val1)
{
int res = val1 - val2;
Hours.Text = Convert.ToString(res);
}
}
if (comboBox1.Text == "am" && comboBox2.Text == "am")
{
Hours.Text = Convert.ToString(val2);
}
if (comboBox1.Text == "pm" && comboBox2.Text == "am")
{
val2 += 12;
int res = val2 - val1;
Hours.Text = Convert.ToString(res);
}
if (comboBox1.Text == "am" && comboBox2.Text == "pm")
{
val2 += 12;
int res = val2 - val1;
Hours.Text = Convert.ToString(res);
}
//----------------------------------------//
if (min1 > min2)
{
int res = min1 - min2;
Min.Text = Convert.ToString(res);
}
if (min2 > min1)
{
int res = min2 - min1;
Min.Text = Convert.ToString(res);
}
int sec1 = Convert.ToInt32(Hours.Text);
int sec2 = Convert.ToInt32(Min.Text);
sec2 = sec2 * 60;
sec1 = sec1 * 60 * 60;
sec1 = sec1 + sec2;
sec.Text = Convert.ToString(sec1);
}
}
}
Post A Comment:
0 comments: