Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,570 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,665 people online right now. Registration is fast and FREE... Join Now!




C - cash register program

 
Reply to this topicStart new topic

C - cash register program

Double Click
30 Nov, 2007 - 11:08 AM
Post #1

New D.I.C Head
*

Joined: 5 Oct, 2007
Posts: 7


My Contributions
Hi,

I am learning C language in college, and i got an assignment, and here is the task:
To develop an integrated cash register and stock control system.

Your application must allow:

Users enter product details which are written to a file. Each product should be identifiable by an ID, starting at 0 for the first product.
Update product details.
Start a transaction
Enter the amount of each product to be added to the transaction.
End the transaction, at which point the stock level is updated.
You may implement as much additional functionality as you wish, for example:

The details of each completed transaction could be stored in a sales file.
A receipt could be printed to a file upon completion of a transaction.

and here is the the code I came up with, I'm getting loads of errors - please help

CODE
#include <stdio.h>
#define MAXPRODAMOUNT 40

struct product_details {
    int prod_id[10];
    char description[MAXPRODAMOUNT];
    int product_price[10];
    int stock_level[10];
}

int main(int argc, char *argv[]){

    void add_product_details(product_details *pd);
    void get_product_details_from_database(FILE*, product_details*);
    //void write_product_to_database(FILE *file_pointer, product_details *pd)
    void write_product_to_database(FILE*, product_details*);
    int get_choice_and_continue(char*);
    int get_stock_choice_and_continue(char *c);
    void change_product_description(product_details *pd);
    void change_product_price(product_details *pd);
    void add_product_stock(product_details *pd);
    void reduce_product_stock(product_details *pd);
    void set_product_stock(product_details *pd);
    void list_product_id(product_details *pd);

    char choice;
    
    FILE *fp;
    product_details r;

    // Check the command line arguments
    if(argc != 2) usage();

    // Open the file
    fp = open_file(argv[1]);

while(get_choice_and_continue(&choice) == 1) {
        switch(choice) {
            case 'A':
            case 'a':
                while(get_stock_choice_and_continue(&choice) == 1) {
                    switch (choice)
                    {
                    case 'A':
                    case 'a':
                        add_product_details(&r);
                        write_product_to_database(fp, r);
                        break;
                    
                    case 'B':
                    case 'b':
                        change_product_description(&r);
                        write_product_to_database(fp, r);
                        break;

                    case 'C':
                    case 'c':
                        change_product_price(&r);
                        write_product_to_database(fp, r);
                        break;
                    
                    case 'D':
                    case 'd':
                        add_product_stock(&r);
                        write_product_to_database(fp, r);
                        break;
                    
                    case 'E':
                    case 'e':
                        reduce_product_stock(&r);
                        write_product_to_database(fp, r);
                        break;

                    case 'F':
                    case 'f':
                        set_product_stock(&r);
                        write_product_to_database(fp, r);
                        break;
                /*    
                    case 'G':
                    case 'g':


                        break;
                    */
                    case 'H':
                    case 'h':
                        list_product_id(&r);
                        get_product_details_from_database(fp, r);
                        break;
                    }
                
                break;
            case 'B':
            case 'b':
                get_match_from_database(fp, &r);
                print_match_details(&r);
                break;
        }
    }

    fclose(fp);

    return 0;
}


//main menu
int get_choice_and_continue(char *c){
    do {
printf("\tMAIN MENU\n");
printf("\nManage Stock\t\t(A)\n");
printf("Manage Sales\t\t(B)\n");
printf("Cash Register\t\t(C)\n");
printf("Exit\t\t\t(C)\n");
printf("\t\t--> \n");
*c = (char)getchar();
getchar();

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}


// manage stock menu
int get_stock_choice_and_continue(char *c) {

    do {
printf("\tSTOCK MANAGEMENT MENU\n");
printf("\nAdd new product\t\t\t(A)\n");
printf("Change product description\t(B)\n");
printf("Change product price\t\t(C)\n");
printf("Add Stock\t\t\t(D)\n");
printf("Remove stock\t\t\t(E)\n");
printf("Set stock\t\t\t(F)\n");
printf("Get product details\t\t(G)\n");
printf("List Product IDs\t\t(H)\n");
printf("Return to main menu\t\t(X)\n");

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'D' && *c != 'd' && *c != 'E' && *c != 'e' && *c != 'F' && *c != 'f' && *c != 'G' && *c != 'g' && *c != 'H' && *c != 'h' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}



// MANAGE SALES MENU

int get_sales_choice_and_continue(char *c) {

    do {
printf("\tSALES MANAGEMENT MENU\n");
printf("\nCalculate total sales\t\t\t(A)\n");
printf("Calculate total sales for product\t(B)\n");
printf("View All Sales\t\t\t\t(C)\n");
printf("View individual sales\t\t\t(D)\n");
printf("Print Sales Receipt\t\t\t(E)\n");
printf("Return to main menu\t\t\t(X)\n");

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'D' && *c != 'd' && *c != 'E' && *c != 'e' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}


//CASH REGISTER MENU

int get_cash_register_choice_and_continue(char *c) {

    do {
printf("\tCASH REGISTER MENU\n");
printf("\nTransaction\t\t(A)\n");
printf("Sub-Total\t\t(B)\n");
printf("Total\t\t\t(C)\n");
printf("Return to main menu\t(X)\n");
} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}

//********************************************************* STOCK MANAGEMENT FUNCTIONS ***********************************************

void get_product_details_from_database(FILE *file_pointer, product_details *fp) {
    fread(fp, sizeof(product_details), 1, file_pointer);
}

void write_product_to_database(FILE *file_pointer, product_details *pd) {
    fwrite(pd, sizeof(product_details), 1, file_pointer);
}


void add_product_details(product_details *pd) {
    printf("Enter product ID: ");
    scanf("%d", &pd->prod_id);
    printf("Enter description : ");
    gets(pd->description);
    printf("Enter price unit (cent): ");
    scanf("%d", &pd->stock_level);
    printf("Stock Level :");
    scanf("%d", &pd->product_price);
    getchar();
    
}
// Change product description
void change_product_description(product_details *pd) {
    int choice;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Price",pd->product_price);
        printf("Enter new description : ");
        gets(pd->description[0]);
        getchar();
}
    
    

// Change product price
void change_product_price(product_details *pd) {
    int choice;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Price",pd->product_price);
    printf("Enter new price : ");
    scanf("%d",&pd->product_price);
    getchar();
    
}

//Add stock

void add_product_stock(product_details *pd) {
    int choice; int x;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Stock Level",pd->stock_level);
        printf("Enter additional stock : ");
        scanf("%d",&x);
        pd->stock_level[0] + x;
        
    }
    
}

//Remove stock

void reduce_product_stock(product_details *pd) {
    int choice; int x;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Stock Level",pd->stock_level);
        printf("Enter stock to remove: ");
        scanf("%d",&x);
        pd->stock_level[0] - x;
        
    }

//Set stock
void set_product_stock(product_details *pd) {
    int choice; int x;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Stock Level",pd->stock_level);
        printf("Enter stock to remove: ");
        scanf("%d",&x);
        pd->stock_level[0] = x;

//List product ID's
void list_product_id(product_details *pd) {
    int i; //int x;

    printf("\tPRODUCTS CURRENTLY IN STOCK");
    for (i = 0;i<10; i++)
    {
        printf("%d. %s\n",pd->prod_id[i],pd->description[i]);
    }
//***************************************** MANAGE SALES FUNCTIONS *****************************************************************


//***************************************** CASH REGISTER FUNCTIONS ****************************************************************
//Transaction
void prod_transaction(product_details *pd) {
    int x;
    int choice;
    int prod_ind;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n %s\t\t-->%d", pd->prod_id,pd->description,"Stock Level",pd->stock_level,"Price",pd->product_price);
        printf("Enter number of units: ");
        scanf("%d",&x);
        prod_ind = (x * pd->product_price);
        prod_ind++;
}
}
}
//subtotal



thanks

User is offlineProfile CardPM
+Quote Post

Pontus
RE: C - Cash Register Program
30 Nov, 2007 - 11:41 AM
Post #2

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
My Contributions
"lots of errors" isn't very explaining. Pls show us wich errors and where they are. Otherwise its a bit though to help u.
User is offlineProfile CardPM
+Quote Post

ShotokanDeity
RE: C - Cash Register Program
30 Nov, 2007 - 12:01 PM
Post #3

D.I.C Head
Group Icon

Joined: 13 Sep, 2007
Posts: 79


My Contributions
I believe you need to declare your prototype functions outside of the main().

edit: I haven't looked in-depth at your code, that was just the first thing that came to mind.

This post has been edited by ShotokanDeity: 30 Nov, 2007 - 12:04 PM
User is offlineProfile CardPM
+Quote Post

Double Click
RE: C - Cash Register Program
30 Nov, 2007 - 12:15 PM
Post #4

New D.I.C Head
*

Joined: 5 Oct, 2007
Posts: 7


My Contributions
QUOTE(manhaeve5 @ 30 Nov, 2007 - 12:41 PM) *

"lots of errors" isn't very explaining. Pls show us wich errors and where they are. Otherwise its a bit though to help u.


Sorry, here is the list of errors:



C:\Programming\test>bcc32 assignment_2.c
Borland C++ 5.5.1 for Win32 Copyright © 1993, 2000 Borland
Assignment_2.c:
Error E2176 Assignment_2.c 11: Too many types in declaration
Error E2111 Assignment_2.c 11: Type 'product_details' may not be defined here
Error E2268 Assignment_2.c 32: Call to undefined function 'usage' in function ma
in(int,char * *)
Error E2268 Assignment_2.c 35: Call to undefined function 'open_file' in functio
n main(int,char * *)
Error E2034 Assignment_2.c 35: Cannot convert 'int' to 'FILE *' in function main
(int,char * *)
Error E2034 Assignment_2.c 47: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 47: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2034 Assignment_2.c 53: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 53: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2034 Assignment_2.c 59: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 59: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2034 Assignment_2.c 65: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 65: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2034 Assignment_2.c 71: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 71: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2034 Assignment_2.c 77: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 77: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2034 Assignment_2.c 89: Cannot convert 'product_details' to 'product_deta
ils *' in function main(int,char * *)
Error E2340 Assignment_2.c 89: Type mismatch in parameter 2 (wanted 'product_det
ails *', got 'product_details') in function main(int,char * *)
Error E2268 Assignment_2.c 96: Call to undefined function 'get_match_from_databa
se' in function main(int,char * *)
Error E2268 Assignment_2.c 97: Call to undefined function 'print_match_details'
in function main(int,char * *)
Error E2034 Assignment_2.c 104: Cannot convert 'int' to 'product_details' in fun
ction main(int,char * *)
Error E2141 Assignment_2.c 109: Declaration syntax error in function main(int,ch
ar * *)
Error E2139 Assignment_2.c 248: Declaration missing ; in function main(int,char
* *)
Warning W8057 Assignment_2.c 248: Parameter 'argv' is never used in function mai
n(int,char * *)
Error E2190 Assignment_2.c 248: Unexpected }
Error E2228 Assignment_2.c 248: Too many error or warning messages
*** 26 errors in Compile ***



User is offlineProfile CardPM
+Quote Post

Pontus
RE: C - Cash Register Program
30 Nov, 2007 - 12:45 PM
Post #5

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
My Contributions
well, here is the code with most of the problems out:
Your most common problem: place struct before product_details
and
use '&' to use a struct as a pointer
CODE

#include <stdio.h>
#define MAXPRODAMOUNT 40

struct product_details{
    int prod_id[10];
    char description[MAXPRODAMOUNT];
    int product_price[10];
    int stock_level[10];
};

void add_product_details(struct product_details *pd);
    void get_product_details_from_database(FILE*,struct product_details*);
    //void write_product_to_database(FILE *file_pointer, product_details *pd)
    void write_product_to_database(FILE*,struct product_details*);
    int get_choice_and_continue(char*);
    int get_stock_choice_and_continue(char *c);
    void change_product_description(struct product_details *pd);
    void change_product_price(struct product_details *pd);
    void add_product_stock(struct product_details *pd);
    void reduce_product_stock(struct product_details *pd);
    void set_product_stock(struct product_details *pd);
    void list_product_id(struct product_details *pd);

int main(int argc, char *argv[]){

    char choice;
    
    FILE *fp;
    struct product_details r;

    // Check the command line arguments
    if(argc != 2) usage();

    // Open the file
    fp = fopen(argv[1],"r");

while(get_choice_and_continue(&choice) == 1) {
        switch(choice) {
            case 'A':
            case 'a':
                while(get_stock_choice_and_continue(&choice) == 1) {
                    switch (choice)
                    {
                    case 'A':
                    case 'a':
                        add_product_details(&r);
                        write_product_to_database(fp, &r);
                        break;
                    
                    case 'B':
                    case 'b':
                        change_product_description(&r);
                        write_product_to_database(fp, &r);
                        break;

                    case 'C':
                    case 'c':
                        change_product_price(&r);
                        write_product_to_database(fp, &r);
                        break;
                    
                    case 'D':
                    case 'd':
                        add_product_stock(&r);
                        write_product_to_database(fp, &r);
                        break;
                    
                    case 'E':
                    case 'e':
                        reduce_product_stock(&r);
                        write_product_to_database(fp, &r);
                        break;

                    case 'F':
                    case 'f':
                        set_product_stock(&r);
                        write_product_to_database(fp, &r);
                        break;
                /*    
                    case 'G':
                    case 'g':


                        break;
                    */
                    case 'H':
                    case 'h':
                        list_product_id(&r);
                        get_product_details_from_database(fp, &r);
                        break;
                    }
                
                break;
            case 'B':
            case 'b':
                get_match_from_database(fp, &r);
                print_match_details(&r);
                break;
        }
    }

    fclose(fp);

    return 0;
}


//main menu
int get_choice_and_continue(char *c){
    do {
printf("\tMAIN MENU\n");
printf("\nManage Stock\t\t(A)\n");
printf("Manage Sales\t\t(B)\n");
printf("Cash Register\t\t(C)\n");
printf("Exit\t\t\t(C)\n");
printf("\t\t--> \n");
*c = (char)getchar();
getchar();

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}


// manage stock menu
int get_stock_choice_and_continue(char *c) {

    do {
printf("\tSTOCK MANAGEMENT MENU\n");
printf("\nAdd new product\t\t\t(A)\n");
printf("Change product description\t(B)\n");
printf("Change product price\t\t(C)\n");
printf("Add Stock\t\t\t(D)\n");
printf("Remove stock\t\t\t(E)\n");
printf("Set stock\t\t\t(F)\n");
printf("Get product details\t\t(G)\n");
printf("List Product IDs\t\t(H)\n");
printf("Return to main menu\t\t(X)\n");

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'D' && *c != 'd' && *c != 'E' && *c != 'e' && *c != 'F' && *c != 'f' && *c != 'G' && *c != 'g' && *c != 'H' && *c != 'h' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}



// MANAGE SALES MENU

int get_sales_choice_and_continue(char *c) {

    do {
printf("\tSALES MANAGEMENT MENU\n");
printf("\nCalculate total sales\t\t\t(A)\n");
printf("Calculate total sales for product\t(B)\n");
printf("View All Sales\t\t\t\t(C)\n");
printf("View individual sales\t\t\t(D)\n");
printf("Print Sales Receipt\t\t\t(E)\n");
printf("Return to main menu\t\t\t(X)\n");

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'D' && *c != 'd' && *c != 'E' && *c != 'e' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}


//CASH REGISTER MENU

int get_cash_register_choice_and_continue(char *c) {

    do {
printf("\tCASH REGISTER MENU\n");
printf("\nTransaction\t\t(A)\n");
printf("Sub-Total\t\t(B)\n");
printf("Total\t\t\t(C)\n");
printf("Return to main menu\t(X)\n");
} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}

//********************************************************* STOCK MANAGEMENT FUNCTIONS ***********************************************

void get_product_details_from_database(FILE *file_pointer,struct product_details *fp) {
    fread(fp, sizeof(struct product_details), 1, file_pointer);
}

void write_product_to_database(FILE *file_pointer,struct product_details *pd) {
    fwrite(pd, sizeof(struct product_details), 1, file_pointer);
}


void add_product_details(struct product_details *pd) {
    printf("Enter product ID: ");
    scanf("%d", &pd->prod_id);
    printf("Enter description : ");
    gets(pd->description);
    printf("Enter price unit (cent): ");
    scanf("%d", &pd->stock_level);
    printf("Stock Level :");
    scanf("%d", &pd->product_price);
    getchar();
    
}
// Change product description
void change_product_description(struct product_details *pd) {
    int choice;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Price",pd->product_price);
        printf("Enter new description : ");
        gets(pd->description[0]);
        getchar();
}
    
    

// Change product price
void change_product_price(struct product_details *pd) {
    int choice;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Price",pd->product_price);
    printf("Enter new price : ");
    scanf("%d",&pd->product_price);
    getchar();
    
}

//Add stock

void add_product_stock(struct product_details *pd) {
    int choice; int x;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Stock Level",pd->stock_level);
        printf("Enter additional stock : ");
        scanf("%d",&x);
        pd->stock_level[0] + x;
        
    }
    
}

//Remove stock

void reduce_product_stock(struct product_details *pd) {
    int choice; int x;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Stock Level",pd->stock_level);
        printf("Enter stock to remove: ");
        scanf("%d",&x);
        pd->stock_level[0] - x;
        
    }

//Set stock
void set_product_stock(struct product_details *pd) {
    int choice; int x;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n", pd->prod_id,pd->description,"Current Stock Level",pd->stock_level);
        printf("Enter stock to remove: ");
        scanf("%d",&x);
        pd->stock_level[0] = x;

//List product ID's
void list_product_id(struct product_details *pd) {
    int i; //int x;

    printf("\tPRODUCTS CURRENTLY IN STOCK");
    for (i = 0;i<10; i++)
    {
        printf("%d. %s\n",pd->prod_id[i],pd->description[i]);
    }
//***************************************** MANAGE SALES FUNCTIONS *****************************************************************


//***************************************** CASH REGISTER FUNCTIONS ****************************************************************
//Transaction
void prod_transaction(struct product_details *pd) {
    int x;
    int choice;
    int prod_ind;
    printf("Enter product ID: ");
    scanf("%d", &choice);
    
        printf("%d. %s\n %s\t\t-->%d\n %s\t\t-->%d", pd->prod_id,pd->description,"Stock Level",pd->stock_level,"Price",pd->product_price);
        printf("Enter number of units: ");
        scanf("%d",&x);
        prod_ind = (x * pd->product_price);
        prod_ind++;
}
}
}
//subtotal


User is offlineProfile CardPM
+Quote Post

Double Click
RE: C - Cash Register Program
30 Nov, 2007 - 01:04 PM
Post #6

New D.I.C Head
*

Joined: 5 Oct, 2007
Posts: 7


My Contributions
thanks a mill,
still need to make it work and add more functionality.
Great help!
User is offlineProfile CardPM
+Quote Post

Pontus
RE: C - Cash Register Program
30 Nov, 2007 - 02:19 PM
Post #7

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
My Contributions
Thats what this forum is for biggrin.gif. I hope u will learn much more.
User is offlineProfile CardPM
+Quote Post

Double Click
RE: C - Cash Register Program
2 Dec, 2007 - 02:53 AM
Post #8

New D.I.C Head
*

Joined: 5 Oct, 2007
Posts: 7


My Contributions
Hi,
I have worked a bit more on the code, now I am getting 1 error, and I can't see how to fix it, please help!!!

Here is the error : Error E2141 moni.c 166: Declaration syntax error in function get_choice_and_continue(char *)

and the code:
CODE
#include <stdio.h>
#define MAXPRODAMOUNT 40

struct product_details{
    int prod_id[10];
    char description[MAXPRODAMOUNT];
    int product_price[10];
    int stock_level[10];
};

    int get_choice_and_continue(char*);
    void usage();
    void add_product_details(product_details *pd);
    void get_product_details_from_database(FILE*,product_details*);
    //void write_product_to_database(FILE *file_pointer, product_details *pd)
    void write_product_to_database(FILE*,product_details*);
    int get_stock_choice_and_continue(char*);
    void change_product_description(product_details*);
    void change_product_price(product_details*);
    void add_product_stock(product_details*);
    void reduce_product_stock(product_details*);
    void set_product_stock(product_details*);
    void list_product_id(product_details*);
    void gets_product_details(product_details*);
    void get_sales_choice_and_continue(product_details*);
    void get_cash_register_choice_and_continue(product_details*);

int main(int argc, char *argv[]){

    char choice;
    
    FILE *fp;
    struct product_details r;

   /// Check the command line arguments
    if(argc != 2) usage();

    // Open the file
    fp = fopen(argv[1],"r");

while(get_choice_and_continue(&choice) == 1) {
        switch(choice) {
            case 'A':
            case 'a':
                while(get_stock_choice_and_continue(&choice) == 1) {
                    switch (choice)
                    {
                    case 'A':
                    case 'a':
                        add_product_details(&r);
                        write_product_to_database(fp, &r);
                        break;
                    
                    case 'B':
                    case 'b':
                        change_product_description(&r);
                        write_product_to_database(fp, &r);
                        break;

                    case 'C':
                    case 'c':
                        change_product_price(&r);
                        write_product_to_database(fp, &r);
                        break;
                    
                    case 'D':
                    case 'd':
                        add_product_stock(&r);
                        write_product_to_database(fp, &r);
                        break;
                    
                    case 'E':
                    case 'e':
                        reduce_product_stock(&r);
                        write_product_to_database(fp, &r);
                        break;

                    case 'F':
                    case 'f':
                        set_product_stock(&r);
                        write_product_to_database(fp, &r);
                        break;
                  
                    case 'G':
                    case 'g':
                        
                        gets_product_details(&r);
                        break;
                    
                    case 'H':
                    case 'h':
                        list_product_id(&r);
                        get_product_details_from_database(fp, &r);
                        break;
                    }
            }
                break;
          /*  case 'B':
            case 'b':
                while (get_sales_choice_and_continue(&choice) == 1)
                {
                switch (choice)
                {
                case 'A':
                case 'a':

                    break;
                
                case 'B':
                case 'b':

                    break;
                
                case 'C':
                case 'c':

                    break;

                case 'D':
                case 'd':

                    break;

                case 'E':
                case 'e':

                    break;
                }
        }
              break;*/

              case 'C':
              case 'c':
                  get_cash_register_choice_and_continue(&r);
                
                
        }
        break;
    }

    fclose(fp);

    return 0;
}


//main menu
int get_choice_and_continue(char *c){
    do {
printf("\tMAIN MENU\n");
printf("\nManage Stock\t\t(A)\n");
printf("Manage Sales\t\t(B)\n");
printf("Cash Register\t\t(C)\n");
printf("Exit\t\t\t(C)\n");
printf("\t\t--> \n");
*c = (char)getchar();
getchar();

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;


// manage stock menu
int get_stock_choice_and_continue(char *c) {

    do {
printf("\tSTOCK MANAGEMENT MENU\n");
printf("\nAdd new product\t\t\t(A)\n");
printf("Change product description\t(B)\n");
printf("Change product price\t\t(C)\n");
printf("Add Stock\t\t\t(D)\n");
printf("Remove stock\t\t\t(E)\n");
printf("Set stock\t\t\t(F)\n");
printf("Get product details\t\t(G)\n");
printf("List Product IDs\t\t(H)\n");
printf("Return to main menu\t\t(X)\n");

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'D' && *c != 'd' && *c != 'E' && *c != 'e' && *c != 'F' && *c != 'f' && *c != 'G' && *c != 'g' && *c != 'H' && *c != 'h' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x')
    {
        get_choice_and_continue;
    }
    else return 1;
}



// MANAGE SALES MENU

int get_sales_choice_and_continue(char *c) {

    do {
printf("\tSALES MANAGEMENT MENU\n");
printf("\nCalculate total sales\t\t\t(A)\n");
printf("Calculate total sales for product\t(B)\n");
printf("View All Sales\t\t\t\t(C)\n");
printf("View individual sales\t\t\t(D)\n");
printf("Print Sales Receipt\t\t\t(E)\n");
printf("Return to main menu\t\t\t(X)\n");

} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'D' && *c != 'd' && *c != 'E' && *c != 'e' && *c != 'X' && *c != 'x');

    if(*c == 'X' || *c == 'x') return 0;
    else return 1;
}


//CASH REGISTER MENU

int get_cash_register_choice_and_continue(char *c) {
    char choice;
    int x;
    int id;
    int prod_id[10];
    int prod_sum[10];
    int subtotal;
    int total;
    do {
printf("\tCASH REGISTER MENU\n");
printf("\nTransaction\t\t(A)\n");
printf("Sub-Total\t\t(B)\n");
printf("Total\t\t\t(C)\n");
printf("Return to main menu\t(X)\n");
printf("\t\t--> %c",&choice);
getchar();
switch (choice)
{
case 'A':
case 'a':

    printf("Enter product ID: ");
    scanf("%d",&id);
    printf("%d. %s\n %s\t\t-->%d\n %s\t\t-->%d", pd->prod_id[id],pd->description[id],"Stock Level",pd->stock_level[id],"Price",pd->product_price[id]);
    printf("Enter number of units: ");
    scanf("%d",&x);
    prod_sum[id] = (x * pd->product_price[id]);
    prod_sum[id]++;
    subtotal = prod_sum[id];

    break;

case 'B':
case 'b':
    
    printf("Sub Total : \t\t--> %d",subtotal);

    break;

case 'C':
case 'c':

    total = (subtotal*1.21);
    printf("Total \t\t-->%d",total);

    break;
}


} while(*c != 'A' && *c != 'a' && *c != 'B' && *c != 'b'&& *c != 'C' && *c != 'c' && *c != 'X' && *c != 'x');

    if(*c