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

Related Questions

I am pretty new at C# and .NET, but I've made this code to
I have a problem, and I made this test code to show you my
I've made this piece of code, it will re-size images on the fly, if
I have made this code: var foo=document.createElement(div); var childs=foo.getElementsByTagName(*); console.log(childs.length);//0 OK var a=document.createElement(a); foo.appendChild(a);
I have made this code to open a database(created in SQLite browser) stored in
How can I improve this code? What has made this long winded is the
Ok. I've made this awe-crap-code Exporting table to XLS (but still no idea how
I have a line, which is a sprite made by using this code CGPoint
I made this little function from code snippets around the net. It does what
I have made customized user registration page. and i have made that on theme

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.