首页 > 用户发贴区 > 编程问题提问区 > 请各位高手帮忙
2008
09-18

/* Note:Your choice is C IDE */
#include “stdio.h”


struct time
{
 int hour;
 int minutes;
 int seconds;
};


int main( void )
{
    struct time timeupdate ( struct time now );
    struct currenttime; struct nexttime;
   
    printf (“enter the time ( hh: mm: ss )”);
    scanf (“%i:%i:%i”, &currenttime.hour, &currenttime.minutes, &currenttime.seconds );
   
    nexttime = timeupdate (currenttime);
    printf (“updated time is %.2i:%.2i:%.2i\n”,nexttime.hour, nexttime.minutes, nexttime.seconds);
   
    return 0;
}


struct time timeupdate ( struct time now )
{
 
 ++now.seconds;
 if ( seconds == 60 ) {
  now.seconds = 0;
  ++now.minutes;
 
 if ( minutes == 60) {
  now.minutes = 0;
  ++now.hour;
  
  if ( now.hour == 24 ) {
   now.hour = 0;
  }
 }
 return now;
}


请各位高手帮忙》有 3 条评论

  1. bowen 说:

    钟表程序/》

  2. mhjerry 说:

    /* Note:Your choice is C IDE */
    #include “stdio.h”

    struct time
    {
     int hour;
     int minutes;
     int seconds;
    };

    int main( void )
    {
        struct time timeupdate ( struct time now );
        struct time currenttime; struct time nexttime;
       
        printf (“enter the time ( hh: mm: ss )”);
        scanf (“%i:%i:%i”, &currenttime.hour, &currenttime.minutes, &currenttime.seconds );
       
        nexttime = timeupdate (currenttime);
        printf (“updated time is %.2i:%.2i:%.2i\n”,nexttime.hour, nexttime.minutes, nexttime.seconds);
       
        return 0;
    }

    struct time timeupdate ( struct time now )
    {
     
     int seconds;
     int minutes;

     ++now.seconds;
     if ( seconds == 60 )
     {
      now.seconds = 0;
      ++now.minutes;
     
    }
     
      if ( minutes == 60)
      {
        now.minutes = 0;
        ++now.hour;
      }
     
      if ( now.hour == 24 )
      {
       now.hour = 0;
      }
     
     return now;
    }

    粗体为修改!

  3. mhjerry 说:

    都是一些语法错误,小心就好了!

留下一个回复