Nautical bell: Difference between revisions
→{{header|C}}
m (→{{header|C}}: remove attribution) |
|||
Line 144:
=={{header|C}}==
Implementation corrected, sounds the system bell as per nautical standards.
<lang C>
/*Abhishek Ghosh, Original : 20th September 2017, Corrected : 25th September 2017*/
<lang C>#include<unistd.h>▼
#include<stdio.h>
#include<time.h>
#define
#define LONGLAG 2000
int main(){
int i,times,hour,min,sec,min1,min2;
time_t t;
Line 163 ⟶ 166:
currentTime = localtime(&t);
min = currentTime->tm_min;
hour = 12;
▲ if(currentTime->tm_min==0 && currentTime->tm_sec==0){
min = 0;
printf("\nIt is now %d:00 %s. Sounding the bell %d times.",times,(currentTime->tm_hour>11)?"PM":"AM",times);▼
sec = 0;
if((min==0 || min==30) && sec==0)
for(i=0;i<times;i++){▼
times = ((hour*60 + min)%240)%8;
printf("\a");▼
if(times==0){
}
if(min==0){
min1 = 0;
min2 = 0;
}
else{
min1 = 3;
}
if((min==0 || min==30) && sec==0){
▲ printf("\nIt is now %d:
▲ printf("\a");
(i%2==0)?sleep(LONGLAG):sleep(SHORTLAG);
}
}
}
return 0;
}
</lang>
|