旧的交付时间+ 25%=新的持续时间(军事时间)我一直得到00为我的最终答案帮助! [英] Old duration of delivery time + 25% = New duration (military time) I keep getting 00 for my final answer help!

查看:58
本文介绍了旧的交付时间+ 25%=新的持续时间(军事时间)我一直得到00为我的最终答案帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// File Prologue
// Name: Logan Ballard
// Project: Project 3
// Date: 11/6/14


// I declare that the following source code was written by me, or provided
// by the instructor for this project. I understand that copying
// source code from any other source constitutes cheating, and that I will
// receive a zero grade on this project if I am found in violation of
// this policy.
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 GGDS
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //Closes program
            this.Close();
        }

        private void calcNewDurationBtn_Click(object sender, EventArgs e)
        {
            //Where the magic happens
            //Calculate new duration of trip from the given starting and ending time
            const int HUNDRED = 100;
            const double TWENTYFIVEPERC = .25;
            const int MINPERHOUR = 60;
            //CONSTANTS
            int startTime = int.Parse(startingTimeTxtBx.Text);
            int endTime = int.Parse(endingTimeTxtBx.Text);
            //USERGIVEN VARIABLES
            int hours1 = startTime / HUNDRED;
            int minutes1 = startTime % HUNDRED;
            int hours2 = endTime / HUNDRED;
            int minutes2 = endTime % HUNDRED;
            int hoursInMinDuration = (hours2 - hours1) * MINPERHOUR;
            int minDuration = minutes2 - minutes1;
            //************************************************************
            int newHoursInMin = hoursInMinDuration * (int)TWENTYFIVEPERC;
            int newHours = newHoursInMin / MINPERHOUR;
            int newMinutes = minDuration * (int)TWENTYFIVEPERC;
            string strHours = newHours.ToString();
            strHours = Convert.ToString(newHours);
            strHours = string.Format("{0}", newHours);
            strHours = string.Empty + newHours;
            strHours = new StringBuilder().Append(newHours).ToString();

            string strMinutes = newMinutes.ToString();
            strMinutes = Convert.ToString(newMinutes);
            strMinutes = string.Format("{0}", newMinutes);
            strMinutes = string.Empty + newMinutes;
            strMinutes = new StringBuilder().Append(newMinutes).ToString();
            //string strHours = newHours.ToString();
            //string strMinutes = newMinutes.ToString();
            newDurationTxtBx.Text = (strHours + strMinutes);
            //int totalMin = hoursInMin + minutes;
            //************************************************************
            //# of Mario's Clicked
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Logan Ballard\nB7\nProject #3");
        }

        private void startingTimeTxtBx_TextChanged(object sender, EventArgs e)
        {

        }

        private void endingTimeTxtBx_TextChanged(object sender, EventArgs e)
        {

        }

        private void newDurationTxtBx_TextChanged(object sender, EventArgs e)
        {

        }

        private void numMarioClickedTxtBx_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

推荐答案

int newHoursInMin = hoursInMinDuration * (int)TWENTYFIVEPERC;
int newMinutes = minDuration * (int)TWENTYFIVEPERC;



newHoursInMin和newMinutes将始终为零,

尝试使用


newHoursInMin and newMinutes will be always zero,
try with

int newHoursInMin = (int)(hoursInMinDuration * TWENTYFIVEPERC);
int newMinutes = (int)(minDuration * TWENTYFIVEPERC);





原因是(int)0.25 为零。


这篇关于旧的交付时间+ 25%=新的持续时间(军事时间)我一直得到00为我的最终答案帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆