Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- char cake_name[255][255];
- int flour[255];
- int sugar[255];
- int butter[255];
- int egg[255];
- char cheese_type[255][255];
- int cheese[255];
- char softness[255][255];
- char sweet[255][255];
- char extra_cheese[255][255];
- int total = 0;
- void clear(){
- for( int i = 0 ; i < 30 ; ++i ){
- printf("\n");
- }
- }
- void create_cake(){
- //name validation
- int flag;
- do{
- do{
- flag = 0;
- printf("Cake Name : ");
- scanf("%[^\n]", &cake_name[total]);fflush(stdin);
- for( int i = 0 ; i < strlen(cake_name[total]) ; ++i ){
- if( isalpha(cake_name[total][i]) ){}
- else{
- flag = 1;
- }
- }
- }while( strlen(cake_name[total]) < 3 || strlen(cake_name[total]) > 10 );
- }while( flag == 1 );
- //flour validation
- do{
- printf("flour : ");
- scanf("%d", &flour[total]);fflush(stdin);
- }while( flour[total] < 30 || flour[total] > 60 );
- //sugar validation
- do{
- printf("sugar : ");
- scanf("%d", &sugar[total]);fflush(stdin);
- }while( sugar[total] < 30 || sugar[total] > 60 );
- //butter validation
- do{
- printf("butter : ");
- scanf("%d", &butter[total]);fflush(stdin);
- }while( butter[total] < 20 || butter[total] > 60 );
- //egg validation
- do{
- printf("egg : ");
- scanf("%d", &egg[total]);fflush(stdin);
- }while( egg[total] < 2 || egg[total] > 5 );
- //cheese type validation
- do{
- printf("cheese type : ");
- scanf("%[^\n]", &cheese_type[total]);fflush(stdin);
- }while( strcmp(cheese_type[total], "Cream") != 0 && strcmp(cheese_type[total], "Cheddar") != 0 );
- //cheese validation
- do{
- printf("cheese : ");
- scanf("%d", &cheese[total]);fflush(stdin);
- }while( cheese[total] < 100 || cheese[total] > 200 );
- //softness validation
- if( flour[total] < 41 ){
- strcpy(softness[total], "Cotton");
- }else if( flour[total] >= 41 && flour[total] <= 50 ){
- strcpy(softness[total], "Soft");
- }else{
- strcpy(softness[total], "Normal");
- }
- //sweet validation
- if( sugar[total] < 41 ){
- strcpy(sweet[total], "Normal");
- }else if( sugar[total] >= 41 && sugar[total] <= 50 ){
- strcpy(sweet[total], "Sweet");
- }else{
- strcpy(sweet[total], "Sugary");
- }
- //extra cheese validation
- if( cheese[total] <= 150 ){
- strcpy(extra_cheese[total], "No");
- }else{
- strcpy(extra_cheese[total], "Yes");
- }
- printf("Success!");
- getchar(); //untuk tahan layar menu
- total++;
- }
- void view_cake(){
- //no data validation
- if( total == 0 ){
- printf("No Data");
- }else{
- for( int i = 0 ; i < total ; ++i ){
- printf("%d %s %s %s %d %d %s %s\n",(i+1), cake_name[i], softness[i], sweet[i], butter[i], egg[i], extra_cheese[i], cheese_type[i]);
- }
- printf("Press Enter to continue");
- }
- getchar(); //untuk tahan layar menu
- }
- int main(){
- int menu = 0;
- do{
- clear(); //untuk hapus layar
- printf("1. Create Cake\n");
- printf("2. View Cake\n");
- printf("3. Exit\n");
- printf("Choose : ");
- scanf("%d", &menu);fflush(stdin);
- clear();
- if( menu == 1 ){
- create_cake();
- }
- else if( menu == 2 ){
- view_cake();
- }
- }while( menu != 3 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement