Skip to content

Instantly share code, notes, and snippets.

@Khuirul-Huda
Created February 10, 2022 06:27
Show Gist options
  • Save Khuirul-Huda/063f1d46ea53c0794aa3aa8592db800e to your computer and use it in GitHub Desktop.
Save Khuirul-Huda/063f1d46ea53c0794aa3aa8592db800e to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void generateTicket() {
int i;
char random[26]="abcdefghijklmnopqrstuvwxyz";
char tiket[8];
for (i = 0; i < 8; ++i) {
tiket[i] = random[rand() % (sizeof(random) - 1)];
printf("%c ", tiket[i]);
}
tiket[8] = 0;
}
int main() {
int age;
int minAge = 10;
short height;
short minHeight = 140;
time_t my_time;
struct tm * timeinfo;
time( & my_time);
timeinfo = localtime( & my_time);
char allowed[] = "\nSelamat! kamu boleh naik wahana ini";
char denied[] = "\nMaaf kamu tidak boleh naik wahana ini untuk saat ini";
printf("%s", "Wahana Bermain Galaxy");
printf(" Tahun %d", timeinfo -> tm_year + 1900);
printf("%s", "\n\nMasukkan umur kamu: ");
scanf("%d", & age);
printf("%s", "\nMasukkan tinggi badan kamu (cm): ");
scanf("%hd", & height);
printf("\nUmur : %d", age);
printf("\nTinggi badan (cm) : %hd", height);
srand(time(NULL));
//nested if else
if (age > 10) {
if (height > minHeight) {
printf("%s", allowed);
printf("%s", "\nKode tiket: ");
generateTicket();
} else {
printf("%s", denied);
}
} else {
printf("%s", denied);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment