Jump to content
Fórum Script Brasil
  • 0

Relógio manual e Despertador em C


Alan Zanatta

Question

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<Windows.h>

//------------------------------------------------
int hora,min,seg,op,op2,soma;
int hrdesp,mindesp,segdesp;      //VARIAVEIS
int h=0,m=0,s=0;
//------------------------------------------------

int validahora() {
    if(hora > 23) {
        return 1;
    }
    return 0;
}

int validamin() {
    if(min > 59) {
        return 1;
    }
    return 0;
}

int validaseg() {
    if(seg > 59) {
        return 1;
    }
    return 0;
}

int main() {

    do {
        system("cls");
        cprintf("\n      RELÓGIO EM C\n\n");
        cprintf(" [1] RELÓGIO(DESPERTADOR)\n");
        printf(" [0] SAIR ");
        scanf("%d",&op);

        switch(op) {

        case 1: system("cls");

            cprintf("\n RELÓGIO EM C\n\n");
            printf(" HORAS: ");      //HORA
            scanf("%d",&hora);

            if(validahora()) {
                system("cls");
                printf("\n Hora invalida");

                getch();
                break;
            }

            printf(" MINUTOS: ");     //MINUTOS
            scanf("%d",&min);

            if(validamin()) {
                system("cls");
                printf("\n Minuto invalido");

                getch();
                break;
            }

            printf(" SEGUNDOS: ");     //SEGUNDOS
            scanf("%d",&seg);

            if(validaseg()) {
                system("cls");
                printf("\n Segundo invalido");

                getch();
                break;
            }

            h=hora;
            m=min;
            s=seg;

            printf("\n\n DESPERTADOR (1 SIM/2 não): ");
            scanf("%d",&op2);

            switch(op2) {

            case 1: system("cls");
                printf("\n CONFIGURAR DESPERTADOR");
                printf("\n\n HORA: ");
                scanf("%d",&hrdesp);
                printf(" MINUTOS: ");
                scanf("%d",&mindesp);

                soma=hrdesp+mindesp;

                break;
            }

            while(1) {

                Sleep(1000); //intervalo de 1 segundo para contagem

                s++;
                if (s>59) {
                    s=0;
                    m++;
                }

                if (m>59) {
                    m=0;
                    h++;
                }

                if (h>23) {
                    h = 0;
                }
                system("cls");

                printf("\n HR MIN SEG\n");
                cprintf(" %.2d  %.2d  %.2d ",h,m,s);

                if(soma>1) {
                    printf("| DESPERTADOR ATIVO %.2d:%.2d",hrdesp,mindesp);
                    if(soma == h+m) {
                        for(int i=0; i<10; i++) {
                            system("cls");
                            printf("\n");

                            printf("  \n DESPERTADOR         ",hrdesp,mindesp);
                            system("cls");
                            printf("\a\n\n DESPERTADOR  %.2d:%.2d",hrdesp,mindesp);
                        }
                        
                        soma=0;

                    }
                }
            }
        }

    }while(op != 0);

    return 0;
}

Edited by kuroi
Adicionar tag CODE
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...