diff --git a/admin_user.h b/admin_user.h index 9f9533f..845d470 100644 --- a/admin_user.h +++ b/admin_user.h @@ -38,15 +38,13 @@ void admin_menu(){ if(user == NULL){//invalid user return; } - printf("Welcome %s(%s)\n", user->name,user->role); - char * Items = { + char * Items[] = { "Inventory control", "Transaction control", "User control", "Role control", }; - choice = choices_selecter(Items,4) - switch (choice) + switch (choices_selecter(Items,4,strcat("Welcome ")"""%s(%s)\n", user->name,user->role)) { case 1://action with inventory inv_control(); @@ -137,7 +135,7 @@ void inv_control(){ do{ choice = prompt_inv_control(); switch (choice){ - case 1://list + case 1:;//list //add a new element with product name new item //for item control struct inventory db = read_db_invt(); @@ -736,7 +734,7 @@ struct Map* sortTrans(struct transaction db,int choice){ switch(choice){ case 1: - case 2: + case 2:; long long temp = (long long)db.row[i].time.second+ db.row[i].time.minute*60 + db.row[i].time.hour*3600 + db.row[i].date.day*86400 + db.row[i].date.month*2592000 + db.row[i].date.year*31104000; long long* tempstar = malloc(sizeof(long long)); *tempstar = temp; @@ -744,19 +742,19 @@ struct Map* sortTrans(struct transaction db,int choice){ break; case 3: - case 4: + case 4:; long* tempstar2 = malloc(sizeof(long)); *tempstar2 = db.row[i].barcode; map[i].value = (void*)tempstar2; break; case 5: - case 6: + case 6:; int* tempstar3 = malloc(sizeof(int)); *tempstar3 = db.row[i].quantity; map[i].value = (void*)tempstar3; break; case 7: - case 8: + case 8:; long temp4 = lround(db.row[i].price * db.row[i].quantity * 10000);//clear all decimal places long* tempstar4 = malloc(sizeof(long)); *tempstar4 = temp4; @@ -982,20 +980,20 @@ struct Map* sortUser(struct user db,int choice){ map[i].key = i; switch(choice){ case 1: - case 2: + case 2:; char* temp = malloc(sizeof(char) * 100); strcpy(temp,db.row[i].name); map[i].value = (void*)temp; break; case 3: - case 4: + case 4:; char* temp2 = malloc(sizeof(char) * 100); strcpy(temp2,db.row[i].role); map[i].value = (void*)temp2; break; case 5: - case 6: + case 6:; long* tempstar3 = malloc(sizeof(long)); *tempstar3 = db.row[i].id; map[i].value = (void*)tempstar3; diff --git a/main.c b/main.c index 1a673d7..207532c 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #endif #ifndef CUSTOM_H #define CUSTOM_H @@ -60,4 +61,4 @@ int main(){ } while (check); return 0; -} \ No newline at end of file +} diff --git a/normal_user.h b/normal_user.h index 9de73bf..020d60d 100644 --- a/normal_user.h +++ b/normal_user.h @@ -208,9 +208,9 @@ struct Map* sortItems(struct inventory db, int sort){ break; case 3: - case 4: - long price = db.row[i].price * 100; - long * price_star = malloc(sizeof(long)); + case 4:; + double price = db.row[i].price * 100; + double * price_star = malloc(sizeof(long)); *price_star = price; map[i].value = (void*)price_star;//presume there is no price contain 0.001 break; diff --git a/utils.h b/utils.h index d11a648..79438eb 100644 --- a/utils.h +++ b/utils.h @@ -1,10 +1,14 @@ -int choices_selecter(char * Items,int items) { - int choice =0 +int choices_selecter(char * Items[],int items,char * welcome_message ){ + int choice = 0; do{ - printf("Select An Option:"); + system("cls"); + if ((*welcome_message) !=NULL){ + printf("%s",welcome_message) + } + printf("Select An Option:\n"); int i; - for (i=0, i");