Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
- void clrscr() { system("@cls||clear");}
- struct Node{
- int stock;
- char genre[8];
- struct Node *next;
- };
- void printList(struct Node *n) {
- if(n!=NULL&&n->stock>0){
- printf("[ %-14s | %-3d song(s) ] --> [top]\n",n->genre,n->stock);
- n=n->next;
- }
- while(n != NULL){
- if(n->stock==0){
- n=n->next;
- }else{
- printf("[ %-14s | %-3d song(s) ]\n",n->genre,n->stock);
- n=n->next;
- }
- }
- }
- int main(){
- struct Node* head= NULL;
- head=(struct Node*)malloc(sizeof(struct Node));
- head->next=NULL;
- head->stock=0;
- int ulang=1;
- int counter=0;
- do{
- clrscr();
- printf("JACKIE CD STOCK\n");
- printf("_______________\n\n");
- printf(" CD Stock <STACK>\n");
- printList(head);
- printf("\n\nOption :\n");
- printf("1. Stock of CD\n");
- printf("2. Sell a CD\n");
- printf("3. Exit\n");
- int choice;
- do{
- printf("\n>>> Input choice : ");
- scanf("%d",&choice);
- if(choice<1||choice>3){
- printf("\t\t\t[!] Menu Unavaiable!");
- }
- }while(choice<1||choice>3);
- clrscr();
- switch(choice){
- case 1:{
- if(counter==0){
- char cdgenre[8];
- int rep=0;
- do{
- printf("Input CD Genre [rock/jazz/blues] : ");
- scanf("%s",cdgenre);
- if(strcmp("rock",cdgenre)==0||strcmp("jazz",cdgenre)==0||strcmp("blues",cdgenre)==0){
- rep=1;
- }
- }while(rep==0);
- int song_number;
- rep=0;
- do{
- printf("\nInput the number of songs on the CD [5...12 song<s>] : ");
- scanf("%d",&song_number);
- if(song_number>4&&song_number<13){
- rep=1;
- }
- }while(rep==0);
- if(strcmp("rock",cdgenre)==0){
- strcpy(head->genre,"rock CD");
- }
- if(strcmp("jazz",cdgenre)==0){
- strcpy(head->genre,"jazz CD");
- }
- if(strcmp("blues",cdgenre)==0){
- strcpy(head->genre,"blues CD");
- }
- head->stock=song_number;
- counter++;
- printf("\n--- Add CD Success ---");
- getch();
- }else{
- if(counter>0&&counter<10){
- struct Node* top= NULL;
- top=(struct Node*)malloc(sizeof(struct Node));
- top->next=head;
- head=top;
- char cdgenre[8];
- int rep=0;
- do{
- printf("Input CD Genre [rock/jazz/blues] : ");
- scanf("%s",cdgenre);
- if(strcmp("rock",cdgenre)==0||strcmp("jazz",cdgenre)==0||strcmp("blues",cdgenre)==0){
- rep=1;
- }
- }while(rep==0);
- int song_number;
- rep=0;
- do{
- printf("\nInput the number of songs on the CD [5...12 song<s>] : ");
- scanf("%d",&song_number);
- if(song_number>4&&song_number<13){
- rep=1;
- }
- }while(rep==0);
- if(strcmp("rock",cdgenre)==0){
- strcpy(head->genre,"rock CD");
- }
- if(strcmp("jazz",cdgenre)==0){
- strcpy(head->genre,"jazz CD");
- }
- if(strcmp("blues",cdgenre)==0){
- strcpy(head->genre,"blues CD");
- }
- head->stock=song_number;
- counter++;
- printf("\n--- Add CD Success ---");
- getch();
- }else{
- printf("Stack Overflow!!");
- getch();
- }
- }
- break;
- }
- case 2:{
- if(counter==0){
- printf("--- The CD Storage is Empty ---");
- getch();
- }else{
- head=head->next;
- printf("--- Sell CD Success ---");
- counter--;
- getch();
- }
- break;
- }
- case 3:{
- ulang=0;
- break;
- }
- }
- }while(ulang==1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment