#include struct time { int hh; int mm; int ss; }; struct date { int mm; int dd;
ID: 3533447 • Letter: #
Question
#include struct time { int hh; int mm; int ss; }; struct date { int mm; int dd; int yy; }; struct combined { struct date d; struct time t; }; struct combined nextSec(struct combined x) { int days[] = {31, 28, 31, 30, 31, 31, 30, 31, 30, 31}; x.t.ss++; if (x.t.ss > 59) { x.t.ss = 0; x.t.mm++; } if (x.t.mm > 59) { x.t.mm = 0; x.t.hh++; } if (x.t.hh > 23) { x.t.hh = 0; ++x.d.dd; } if (x.d.dd > days[x.d.mm - 1]) { x.d.dd = 1; x.d.yy++; } if (x.d.mm > 12) { x.d.mm = 1; x.d.yy++; } return x; } void main() { struct combined c; char more; clrscr(); do { printf (" Input date (mm/dd/yyyy) : "); scanf ("%d/%d/%d", &c.d.mm, &c.d.dd, &c.d.yy); printf (" time (hh:mm:ss) : "); scanf ("%d:%d:%d", &c.t.hh, &c.t.mm, &c.t.ss); printf (" Now is %d:%d:5d on %d/%d/%d", c.t.hh, c.t.mm, c.t.ss, c.d.mm, c.d.dd, c.d.yy); c = nextSec(c); printf (" The nect sec is %d:%d:%d on %d/%d/%d", c.t.hh, c.t.mm, c.t.ss, c.d.mm, c.d.dd, c.d.yy); printf (" Do more (Y/N)? "); scanf ("%s", &more); } while (more == 'y' || more == 'Y'); } .h>
Explanation / Answer
//working code please rate
#include<stdio.h>
#include<conio.h>
struct time { int hh; int mm; int ss; };
struct date { int mm; int dd; int yy; };
struct combined { struct date d; struct time t; };
struct combined nextSec(struct combined x)
{
int days[] = {31, 28, 31, 30, 31, 31, 30, 31, 30, 31};
x.t.ss++;
if (x.t.ss > 59)
{
x.t.ss = 0; x.t.mm++;
}
if (x.t.mm > 59)
{
x.t.mm = 0;
x.t.hh++;
}
if (x.t.hh > 23)
{
x.t.hh = 0;
++x.d.dd;
}
if (x.d.dd > days[x.d.mm - 1])
{
x.d.dd = 1;
x.d.yy++;
}
if (x.d.mm > 12)
{
x.d.mm = 1;
x.d.yy++;
}
return x;
}
int main()
{
struct combined c;
char more;
do
{
printf (" Input date (mm/dd/yyyy) : ");
scanf ("%d/%d/%d", &c.d.mm, &c.d.dd, &c.d.yy);
printf (" time (hh:mm:ss) : ");
scanf ("%d:%d:%d", &c.t.hh, &c.t.mm, &c.t.ss);
printf (" Now is %d:%d:5d on %d/%d/%d", c.t.hh, c.t.mm, c.t.ss, c.d.mm, c.d.dd, c.d.yy);
c = nextSec(c);
printf (" The nect sec is %d:%d:%d on %d/%d/%d", c.t.hh, c.t.mm, c.t.ss, c.d.mm, c.d.dd, c.d.yy);
printf (" Do more (Y/N)? ");
scanf ("%s", &more);
}
while (more == 'y' || more == 'Y');
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.