-2

我想创建一个程序,它会询问 min、hours、AM 和 PM,但我想要它做的是在显示当前时间时向当前输入的 mint 添加一个。例如:我将输入小时:5,输入分钟:23 输入 AM 或 PM:AM 并给我新时间为 5:24 AM,我也希望它更改时间和 AM 或 PM,如果输入了一些像这样,输入小时:11 输入分钟:59 输入 AM 或 PM:AM 新时间是 12 00 PM。如果我从凌晨 12:59 到凌晨 1:00,也会更改时间。这是我到目前为止所做的,但不知道如何让时间循环。我也想在没有任何课程的情况下做到这一点。这件事让我很沮丧,无处可去。

#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
    int hr = hr;
        int min = min;
            int period = period;
            currentTime

            int time;
                    time = hr * 60 + min + 1;
                    hr = time / 60;
                    min = time % 60;
                    currentTime = currentTime(5, 59, "AM");
                    cout<<currentTime .hr +" : "+currentTime .min +" "+currentTime .period;
                             cin>>hrs;

}
4

2 回答 2

0

I think this code, would produce a similar output to what you're looking for, but without the loop you wanted to create, because I'm sure that would require a fair few if statements.

I was curious as what this line was doing currentTime because it doesn't look to me like it would do anything at all.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int hr, min;
    char period;

    cout << "Enter Hour" << endl;
    cin >> hr;

    cout << "Enter Minute" << endl;
    cin >> min;
    min++;

    cout << "Enter Period (A or P)" << endl;
    cin >> period;

    cout << "Current Time: " <<  hr << ":" << min << " " << period << "M" << endl;

    _getch();

}
于 2013-10-20T03:30:07.307 回答
-1

Here is an idea of how to accomplish this in C#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            double hrs=0;
            double mins=0;
            DateTime dt = new DateTime(2013, 10, 20, 3, 59, 00);

            //dt = DateTime.Now;

            Console.WriteLine(dt.ToShortTimeString());

            Console.WriteLine("Enter hours:");
            hrs = Convert.ToDouble(Console.ReadLine());
            dt = dt.AddHours(hrs);

            Console.WriteLine("Enter minutes:");
            mins = Convert.ToDouble(Console.ReadLine());
            dt = dt.AddMinutes(mins);

            if (dt.Minute == 59)
                dt = dt.AddMinutes(1);

            Console.WriteLine(dt.ToShortTimeString());
            Console.ReadLine();
        }
    }
}
于 2013-10-20T03:33:31.313 回答