Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:01:02+00:00 2026-05-13T06:01:02+00:00

Hi I made this code that will show when it run a clock and

  • 0

Hi I made this code that will show when it run a clock and then ask the user to enter new seconds and minutes and hours so they will be added to the old clock I did so but the results are wrong where is the mistake

the main

static void Main(string[] args)
    {
        Timer S1 = new Timer();
        S1.Sec = 10;
        S1.Min = 25;
        S1.Hour = 23;
        S1.Read();
        S1.Write();
    }

the timer class

namespace Uni_19
{
class Timer
{
    private int Seconds;
    private int Minutes;
    private int Hours;
    private int Days = 0;

    public int Sec
    {
        get { return Seconds; }
        set
        {
            Seconds = value % 60;
            Minutes += value / 60;
        }
    }
    public int Min
    {
        get { return Minutes; }
        set
        {
            Minutes = value % 60;
            Hour += (value / 60);
        }
    }
    public int Hour
    {
        get { return Hours; }
        set 
        {
            Hours = value % 24;
            Days += value / 24;
        }
    }
    public int Day
    {
        get { return Days; }
        set { Days = Hour / 24; }
    }
    public int AddSec(int A)
    {
        Sec += A;
        return Sec;
    }
    public int AddMin(int B)
    {
        Min += B;
        return Min;
    }
    public int AddHour(int C)
    {
        Hour = Hour + (C % 24);
        return Hour;
    }
    public int AddDay(int D)
    {
        Day += D;
        return Day;
    }
    public void Read()
    {
        Console.WriteLine("Time Is: {0}", Hours + " : " + Minutes + " : " + Seconds);
        Console.Write("Time Added (in Seconds): ");
        Sec = int.Parse(Console.ReadLine());
        Console.Write("Time Added (in Minutes): ");
        Min = int.Parse(Console.ReadLine());
        Console.Write("Time Added (in Houres): ");
        Hour = int.Parse(Console.ReadLine());
    }
    public void Write()
    {
        Console.WriteLine("New Time Is: {0}", AddDay(Day) + " : " + AddHour(Hour) + " : " + AddMin(Min) + " : " + AddSec(Sec));
    }
}
}

thanx in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:01:02+00:00Added an answer on May 13, 2026 at 6:01 am

    You are using the user input for both setting the day and adding to it. The old time is completely overwritten and not used in the calculation.

    Sec = int.Parse(Console.ReadLine());  // Calls the setter 'Sec' which overwrites Seconds.
    

    On top of that, the AddSec routine can return a number greater than 60, which is probably not what you want.

    What is the specification for your homework assignment? Your Timer class is completely unnecessary in .NET because the functionality it provides is already covered by the DateTime and TimeSpan classes. I’m assuming though that you are not allowed to do that otherwise it would make your assignment too easy?

    Possible fix, changing Sec = to AddSec, etc:

    Console.Write("Time Added (in Seconds): ");
    AddSec(int.Parse(Console.ReadLine()));
    Console.Write("Time Added (in Minutes): ");
    AddMin(int.Parse(Console.ReadLine()));
    Console.Write("Time Added (in Houres): ");
    AddHour(int.Parse(Console.ReadLine()));
    
    ...
    
    Console.WriteLine("New Time Is: {0}", Day + " : " + Hour + " : " + Min + " : " + Sec);
    

    Full source code:

    using System;
    
    namespace Uni_19
    {
        class Timer
        {
            private int Seconds;
            private int Minutes;
            private int Hours;
            private int Days = 0;
    
            public int Sec
            {
                get { return Seconds; }
                set
                {
                    Seconds = value % 60;
                    Minutes += value / 60;
                }
            }
            public int Min
            {
                get { return Minutes; }
                set
                {
                    Minutes = value % 60;
                    Hour += (value / 60);
                }
            }
            public int Hour
            {
                get { return Hours; }
                set
                {
                    Hours = value % 24;
                    Days += value / 24;
                }
            }
            public int Day
            {
                get { return Days; }
                set { Days = Hour / 24; }
            }
            public int AddSec(int A)
            {
                Sec += A;
                return Sec;
            }
            public int AddMin(int B)
            {
                Min += B;
                return Min;
            }
            public int AddHour(int C)
            {
                Hour = Hour + (C % 24);
                return Hour;
            }
            public int AddDay(int D)
            {
                Day += D;
                return Day;
            }
            public void Read()
            {
                Console.WriteLine("Time Is: {0}", Hours + " : " + Minutes + " : " + Seconds);
                Console.Write("Time Added (in Seconds): ");
                AddSec(int.Parse(Console.ReadLine()));
                Console.Write("Time Added (in Minutes): ");
                AddMin(int.Parse(Console.ReadLine()));
                Console.Write("Time Added (in Houres): ");
                AddHour(int.Parse(Console.ReadLine()));
            }
            public void Write()
            {
                Console.WriteLine("New Time Is: {0}", Day + " : " + Hour + " : " + Min + " : " + Sec);
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Timer S1 = new Timer();
                S1.Sec = 10;
                S1.Min = 25;
                S1.Hour = 23;
                S1.Read();
                S1.Write();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 265k
  • Answers 265k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer During deferred execution you don't have access to most properties.… May 13, 2026 at 12:21 pm
  • Editorial Team
    Editorial Team added an answer Negative values are accepted. Just use something like: add_filter('the_author','my_function',-1000000); May 13, 2026 at 12:21 pm
  • Editorial Team
    Editorial Team added an answer git-unpack-objects will unpack the objects, but only inside a repo… May 13, 2026 at 12:21 pm

Related Questions

IDE = VS7 or 2002 Hi all, I have a really weird problem here.
Hi (I'm pretty new to this), I have created a portal where the user
I've got a really strange error and any light that anyone can shed on
I have on table named players , then other tables named tries , conversions
I've been looking all over and i can't find anything to fix this problem.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.