Created
November 12, 2018 04:28
-
-
Save ayatmaulana/12d7faf6b64c6fa7255e5f91ab9a1a89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
void showMenu(){ | |
printf("Yogurt Shop\n"); | |
printf("------------\n"); | |
printf("1. Buy Yogurt\n"); | |
printf("2. View History\n"); | |
printf("3. Delete History\n"); | |
printf("4. Exit\n\n"); | |
} | |
int countPrice(char name[50], char topping[50], int size) { | |
// Price = size x pjg karakter nama yogurt x pjg karakter topping x 10 | |
int price = (unsigned)strlen(name) * (unsigned)strlen(topping) * size * 10; | |
return price; | |
} | |
void detailPuchase(char name[50], char topping[50], int size){ | |
int total = countPrice(name, topping, size); | |
printf("\n\n"); | |
printf("Detail Purchase\n"); | |
printf("Name : %s\n", name); | |
printf("Topping : %s\n", topping); | |
printf("Size : %i\n", size); | |
printf("Total : %i\n", total); | |
// char historyFormat = 2 | |
// putc(, fp) | |
FILE * fp; | |
fp = fopen("yogurt.txt","w"); | |
fprintf(fp, "%s \t | %s \t | %i \t | %i \t | \n", name, topping, size, total ); | |
} | |
int main(){ | |
int menuChoice; | |
while(1) { | |
showMenu(); | |
printf("Input Your choice 1-4: "); scanf("%i", &menuChoice); | |
if(menuChoice == 1) { | |
char yogurtName[50], yogurtTopping[50], confirm[1]; | |
int yogurtSize; | |
printf("Input your yogurt [chocolate/vanilla/strawberry]: "); scanf("%s", yogurtName); | |
printf("Input your topping [kitkat/jelly/kiwi/mango]: "); scanf("%s", yogurtTopping); | |
printf("Input your size[100-500]: "); scanf("%i", &yogurtSize); | |
printf("are you sure? y/n : "); scanf("%s", confirm); | |
if(confirm == 'y'){ | |
detailPuchase(yogurtName, yogurtTopping, yogurtSize); | |
} | |
printf("\n\n"); | |
continue; | |
} | |
if(menuChoice == 2) { | |
} | |
if(menuChoice == 3) { | |
} | |
if(menuChoice == 4) { | |
} | |
if(menuChoice == 5) { | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment