locked
Multiplying percentage / getting percentage of int

    Question

  • Trying to find 25% of time2 - time1.
    How do you find a percentage of an int?

    class Program
    {
        public const int minsInHour = 60;
        public const int hunPart = 100;
        public const double delay = .25;
        static void Main()
        {
            // Variable declarations
    
            int time1 = 0;
            int time2 = 0;
            int hours1 = 0;
            int hours2;
            int mins1 = 0;
            int mins2 = 0;
            int newTime = 0;
    
            string txt;
    
            while (true)
            {
                Console.WriteLine("Enter your departure time: ");
                txt = Console.ReadLine();
                time1 = int.Parse(txt);
                mins1 = time1 % hunPart;
                hours1 = time1 /hunPart * minsInHour;
                if (time1 < 1441) break;
            }
    
            while (true)
            {
                Console.WriteLine("Enter your usual arrival time: ");
                txt = Console.ReadLine();
                time2 = int.Parse(txt);
                mins2 = time2 % hunPart;
                hours2 = time2 /hunPart * minsInHour;
                if (time2 < 2401) break;
            }
    
    
            time1 = hours1 + mins1;
            time2 = hours2 + mins2;
    
            int trafficDelay = Convert.ToInt16(delay);
    
            newTime = time2 - time1 * trafficDelay;
    
            Console.WriteLine("{0}", time1);
            Console.WriteLine("{0}", time2);
            Console.WriteLine("{0}", newTime);
    
            Console.ReadLine();

    thanks!!

    Sunday, September 16, 2012 5:21 PM

Answers

All replies