-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.c
More file actions
73 lines (66 loc) · 2.15 KB
/
Copy pathapp.c
File metadata and controls
73 lines (66 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
void tambahBuku(char namaBuku[100][100], int stock[100], int *choose){
printf("Masukkan nama buku : ");
scanf("%s",&namaBuku[*choose]);
printf("Masukkan Stock Buku : ");
scanf("%d",&stock[*choose]);
(*choose)++;
}
void tampilBuku(char namaBuku[100][100], int stock[100], int choose){
for(int i=0;i<choose;i++){
printf("Judul buku ke-%d adalah %s , stock : %d \n ",i+1,namaBuku[i],stock[i]);
}
}
void beliBuku(char namaBuku[100][100],int stock[100],int choose){
int pilihan,jumlahBeli;
for(int i=0;i<choose;i++){
printf("%d. %s => : %d \n",i+1,namaBuku[i],stock[i]);
}
printf("Masukkan Pilihan : ");
scanf("%d",&pilihan);
if(pilihan > 0 && pilihan <= jumlahBeli){
printf("Masukkan jumlah buku yang ingin di beli : ");
scanf("%d",&jumlahBeli);
if(jumlahBeli <= stock[pilihan-1]){
stock[pilihan-1] -= jumlahBeli;
printf("Pembelian buku %s sebanyak %d berhasil..",namaBuku[pilihan-1],jumlahBeli);
}else{
printf("Stock buku tidak cukup...");
}
}else{
printf("Pilihan tidak valid");
}
}
int main(){
char namaBuku[100][100];
int stock[100];
int choose = 0;
int pilihan;
do{
printf("Selamat Datang di Book Store Staditek\n");
printf("1. Tambah Buku \n");
printf("2. Tampil Buku \n");
printf("3. Beli Buku \n");
printf("4. Keluar Aplikasi \n");
printf("Pilih menu : ");
scanf("%d",&pilihan);
switch(pilihan){
case 1 :
tambahBuku(namaBuku,stock,&choose);
break;
case 2 :
tampilBuku(namaBuku,stock,choose);
break;
case 3 :
beliBuku(namaBuku,stock,choose);
break;
case 4 :
printf("Terima kasih telah berbelanja di book store staditek");
break;
default :
printf("Pilian anda tidak ada..!!!");
break;
}
}while(pilihan != 4);
return 0;
}