Ich wollte einen Timer, der auf Benutzereingabe lief wie die meisten Timer-Anwendungen oder eine Eieruhr. Ich schrieb den Code, aber ich komme mit Müll-Werte und kaum funktionierenden Code. Bitte helfen Sie!Wie ich meine Uhr App arbeiten lassen
#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
main(){
int h=0;
int s=0;
int m=0;
printf("Please enter the time you want for the timer.");
printf("Please enter how many hours you want for the timer.(max 24!)");
scanf("%d",&h);
printf("Please enter how many minutes you want for the timer.(max 59!)");
scanf("%d",&m);
printf("Please enter how many seconds you want for the timer.(max 59!)");
scanf("%d",&s);
while (s<=60){
printf(" %d hours %d minutes and %d seconds \n", m ,s);//gives the countdown output
sleep(1); //for delaying in seconds.
s++;// adds one to the second counter
if(s==60){
m++;//adds one to the second counter when seconds reach 60
s=0;//resets seconds value to 0.
}
if(m==60){
h++;
m=0;
}
if(h==24){
printf("The timer has reached Max output!\n");
break;
}
}
getch();
}
Debuggen. Beachten Sie, dass die Schleifenbedingung "s <= 60" nach dem Eintritt in die Schleife nicht wahr ist, da wenn "s == 60" wahr wird, "s" auf "0" gesetzt wird. – MikeCAT
Sie haben * undefined behaviour * aufgerufen, indem Sie nicht genügend Argumente für den Formatbezeichner für 'printf()' angegeben haben. – MikeCAT