C++ problem

Status
Not open for further replies.

mickeymouse

Solid State Member
Messages
7
I have the program below that gives me the following errors:

Build Log

--------------------Configuration: mini_project_final - Win32 Debug--------------------

Command Lines
Creating temporary file "C:\DOCUME~1\Owner\LOCALS~1\Temp\RSP130.tmp" with contents
[
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/mini_project_final.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\Owner\LOCALS~1\Temp\RSP130.tmp"
Creating temporary file "C:\DOCUME~1\Owner\LOCALS~1\Temp\RSP131.tmp" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/mini_project_final.pdb" /debug /machine:I386 /out:"Debug/mini_project_final.exe" /pdbtype:sept
".\Debug\mini_project_final.obj"
]
Creating command line "link.exe @C:\DOCUME~1\Owner\LOCALS~1\Temp\RSP131.tmp"
Output Window
Compiling...
mini_project_final.cpp
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(207) : error C2601: 'numberofcoins' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(223) : error C2601: 'getcoins' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(252) : error C2601: 'convert_getcoins' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(277) : error C2601: 'number_of_coins_entered' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(290) : error C2601: 'string_comparecoins' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(367) : error C2601: 'amount_insert' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(410) : error C2601: 'compare_amount' : local function definitions are illegal
C:\Documents and Settings\Owner\My Documents\Shu Xian\Shu Xian\AP_PBIL\mini_project_final.cpp(505) : fatal error C1004: unexpected end of file found
Error executing cl.exe.



Results
mini_project_final.exe - 8 error(s), 0 warning(s)


the program as follows:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

struct selection{
int customer;
char snack[100];
char password[100];
};
struct tidbits{
int biscuits,potato_chips;
};

struct dispenser{
int total_10, total_20, total_50, total_all;
int total_sale;
int biscuits_sold, potato_chips_sold;
};
struct cost{
int enter_10, enter_20, enter_50;
char combinations[50];
float amount;
};
struct all{
struct selection choice;
struct tidbits supply;
struct dispenser transaction;
struct cost money;
};
void select_snack(struct all *data);
void convert_snack(struct all *data);
void get_stock(struct all *data);
void string_compare(struct all *data);
void numberofcoins(struct all *data);
void getcoins(struct all *data);
void convert_getcoins(struct all *data);
void number_of_coins_entered(struct all *data);
void string_comparecoins(struct all *data);
void amount_insert(struct all *data);
void compare_amount(struct all *data);
void change_return(struct all *data);
void printtransactionfile(struct all data);

main()
{
struct all infro;
select_snack(&infro);
convert_snack(&infro);
get_stock(&infro);
string_compare(&infro);
numberofcoins(&infro);
getcoins(&infro);
convert_getcoins(&infro);
number_of_coins_entered(&infro);
string_comparecoins(&infro);
amount_insert(&infro);
compare_amount(&infro);
change_return(&infro);
printtransactionfile(infro);
return 0;
}

void select_snack(struct all *data)
{
FILE *fp;
FILE *cr;
FILE *ip;

fp=fopen("number_of_customer","w+");
if (fp==NULL)
{
printf("Cannot open file!\n");
exit(1);
}
cr=fopen("customer_input.txt","r+");
if(cr==NULL)
{
printf("Cannot open file!\n");
exit(1);
}
ip=fopen("transaction_file.txt","w+");
if(ip==NULL)
{
printf("Cannot open file!\n");
exit(1);
}

fscanf(fp,"%d",&data->choice.customer);
printf("\t\t\t\t\tWelcome\n");
printf("___________________________\n");
printf("Snacks avaliable in the machince:\n");
printf("biscuits\t\t\t\t\tpotato chips\n");
printf("Please enter your choice(eg.biscuits):");
fflush(stdin);
gets(data->choice.snack);
fprintf(cr,"Customer#%d\n",data->choice.customer +1);
fprintf(cr,"____________________\n");
fprintf(ip,"Customer#%d\n",data->choice.customer +1);
fprintf(ip,"_______________________\n");
fclose(fp);
fclose(cr);
fclose(ip);
return;
}

void convert_snack(struct all *data)
{
char *p=data->choice.snack;
while (*p!=NULL)
{
if(isupper(*p))
{
*p = tolower(*p);
p++;
}
}
return;
}

void get_stock(struct all *data)
{
FILE *ic;
ic=fopen("snack_input.txt","r");
if (ic==NULL)
{
printf("Cannot open file!\n");
exit(1);
}
fscanf(ic,"%d%d",&data->supply.biscuits,&data->supply.potato_chips);
fclose(ic);
return;
}

void string_compare(struct all *data)
{
char *b=data->choice.snack;
struct all infro;
FILE *ec;
FILE *de;
ec=fopen("customer_input.txt","r+");
if (ec==NULL)
{
printf("cannot print file !\n");
exit(1);
}
de=fopen("transaction_file.txt","r+");
if (de==NULL)
{
printf("Cannot open file !\n");
exit(1);
}

if (data->supply.biscuits && data->supply.potato_chips!=0)
{
if (strcmp(b,"biscuits")==0)
{

if (data->supply.biscuits !=0)
{
printf("Biscuit selected\n");
fprintf(ec,"Biscuits selected\n");
fprintf(de,"Biscuits selected\n");
printf("cost:40 cents\n");
}
}
else
{
printf("Biscuits out of stock\n");
exit(1);
}
}
else if (strcmp(b,"potato chips")==0)
{
if (data->supply.potato_chips !=0)
{
printf("Potato chips selected\n");
fprintf(ec,"Potato chips selected\n");
fprintf(de,"Potato chips slelected \n");
printf("Cost: 70Cents\n");
}
else
{
printf("Potato chip out of stock\n");
exit(1);
}
}
else if (strcmp(b,"staff")==0)
{
printf("Please enter password:\n");
}
else
{
printf("Please enter your choice again\n");
select_snack(&infro);
}
if(data->supply.biscuits && data->supply.potato_chips==0)
{
printf("Both potato chip and biscuits are out of stock\n");
exit(1);
}
fclose(ec);
fclose(de);
return;

void numberofcoins(struct all *data)
{
FILE *in;
in=fopen("coins_input.txt","r");
if(in==NULL)
{
printf("Cannot open file\n");
exit(1);
}
fscanf(in,"%d",&data->transaction.total_10);
fscanf(in,"%d",&data->transaction.total_20);
fscanf(in,"%d",&data->transaction.total_50);
fclose(in);
return;
}

void getcoins(struct all *data)
{
char *g = data->choice.snack;
if (strcmp(g,"biscuits")==0)
{
printf("Please insert coins (eg,ten):\n");
fflush(stdin);
gets(data->money.combinations);
}
else if (strcmp(g,"potato chips")==0)
{
printf("Please insert coins (eg.ten):\n");
fflush(stdin);
gets(data->money.combinations);
}
else if (strcmp(g,"staff")==0)
{
fflush(stdin);
gets(data->choice.password);
}
else if (data->money.amount!=0.7||0.4)
{
fflush(stdin);
gets(data->money.combinations);
}

return;
}

void convert_getcoins(struct all *data)
{
char *h=data->money.combinations;
char *v=data->choice.password;


while (h!=NULL)
{
if(isupper(*h))
*h=tolower(*h);
h++;
}



while(*v!=NULL)
{
if(isupper(*v))
*v=tolower(*v);
v++;
}

return;
}

void number_of_coins_entered(struct all *data)
{
FILE *gi;
gi=fopen("coins_input_enter.txt","r");
if (gi==NULL)
{
printf("Cannot open file\n");
exit(1);
}
fscanf(gi,"%d%d%d%d", &data->money.enter_10,&data->money.enter_20,&data->money.enter_50, &data->transaction.total_all);
fclose(gi);
return;
}
void string_comparecoins(struct all *data)
{
char *ge=data->money.combinations;
char *he=data->choice.password;
FILE *fg;
FILE *te;
FILE *gs;
FILE *by;
fg=fopen("customer_input.txt","a+");
if (fg==NULL)
{
printf("Cannot open file!\n");
exit(1);
}
te=fopen("transaction_file.txt","a+");
if (te==NULL)
{
printf("Cannot open file!\n");
exit(1);
}
gs=fopen("coins_input.txt","w+");
if (gs==NULL)
{
printf("Cannot open file !\n");
exit(1);
}
by=fopen("coins_input_enter_customer.txt","r+");
if (by==NULL)
{
printf("Cannot open file!\n");
exit(1);
}

if (strcmp(ge,"ten")==0)
{
printf("10Cent inserted\n");
data->transaction.total_10=data->transaction.total_10 +1;
data->money.enter_10=data->money.enter_10+1;
fprintf(fg,"%s",data->money.combinations);
fprintf(te,"%s",data->money.combinations);
fprintf(te,"Total ten-cents coins left:%d",&data->transaction.total_10);
fprintf(by,"Customer#%d\n",&data->choice.customer);
}
else if (strcmp(ge,"twenty")==0)
{
printf("20 Cents inserted\n");
data->transaction.total_20=data->transaction.total_20 +1;
data->money.enter_20=data_.money.enter_20 +1;
fprintf(fg,"%s",data->money.combinations);
fprintf(te,"%s",data->money.combinations);
fprintf(te,"Total twenty-cents coins left:%d",&data->transaction.total_20);
fprintf(by,"Customer#%d\n",&data->choice.customer);
}
else if (strcmp(ge,"fifty")==0)
{
printf("50 Cents inserted\n");
data->transaction.total_50=data->transaction.total_50 +1;
data->money.enter_50=data->money.enter_50 +1;
fprintf(fg,"%s",data->money.combinations);
fprintf(te,"%s",data->money.combinations);
fprintf(te,"Total fifty-cents coins left:%d",&data->money.total_50);
fprintf(by,"Customer#%d",&data->choice.customer);
}
else if (strcmp(he,"abc")==0)
{
printf("Staff logging on.......\n");
}
else
{
getcoins;
}
fclose(fg);
fclose(te);
flcose(by);
fclose(gs);
return;
}
void amount_insert(struct all *data)
{
char *e=data->money.combinations;
char *i=data->choice.password;
char *u=data->choice.snack;
data->money.amount=0;
if (strcmp(u,"biscuits")==0)
{
if (strcmp(e,"ten")==0)
{
data->money.amount=data->money.amount + 0.1;
}
else if (strcmp(e,"twenty")==0)
{
data ->money.amount=data->money.amount +0.2;
}
else if (strcmp(e,"fifty")==0)
{
data->money.amount=data->momey.amount+0.5;
}
}
else if (strcamp(e,"potato chips")==0)
{
if (strcmp(e,"ten")==0)
{
data->money.amount=data->money.amount + 0.1;
}
else if (strcmp(e,"twenty")==0)
{
data->money.amount= data->money.amount + 0.2;
}
else if (strcmp(e,"fifty")==0)
{
data->money.amount= data->money.amount +0.5;
}
}
else if (strcmp(i,"abc")==0)

printf("Successfully log on\n");

return;
}

void compare_amount(struct all *data)
{
char *k=data->choice.snack;
data->transaction.biscuits_sold=0;
float *c=data->money.amount;
FILE *io;
FILE *pe;
FILE *us;
io=fopen("customer_input.txt","a+");
if (io==NULL)
{
printf("Cannot open file !\n");
exit(1);
}
pe=fopen("trasaction_file.txt","a+");
if (pe==NULL)
{
printf("Cannot open file\n");
exit(1);
}
us=fopen("snack_input.txt","w+");
if(us==NULL)
{
printf("Cannot open file !\n");
exit(1);
}
if (strcmp(k,"biscuits")==0)
{
if (c>0.4)
{
printf("Please insert more coins\n");
getcoins;
}
else if (c==0.40)
{
printf("Fourty cents inserted \n");
printf("1 packet of biscuit dispersed\n");
data->supply.biscuits=data->supply.biscuits-1;
data->transaction.biscuits_sold=data->transaction.biscuits_sold+1;
fprintf(io,"A packet of biscuit sold\n");
fprintf(io,"Amount enter:%.2f\n"&data->money.amount);
fprintf(pe,"Amount enter:%.2f\n"&data->money.amount);
fprint(pe,"No change given\n");
fprintf(pe,"%d packet of biscuits sold\n",data->transaction.biscuits_sold);
}
else if (c>0.4)
{
printf("%f inserted\n",&data->money.amount);
printf("1 packet of biscuit dispersed\n");
data->supply.biscuits=data->supply.biscuits-1;
data->transaction,biscuits_sold=data->transaction.biscuits_sold +1;
fprintf(io,"A packet of biscuit sold\n");
fprintf(io,"Amount enter:%.2f\n"&data->money.amount);
fprintf(pe,"Amount enter:%.2f\n"&data->money.amount);
fprintf(pe,"%d packet of biscuits sold\n",&data->transaction.biscuits_sold);
}
}
else if (strcmp(k,"potato chips")==0)
{
if (c>0.7)
{
printf("Please insert more coins\n");
getcoins;
}
else if (c==0.7)
{
printf("Seventy cents inserted \n");
printf("1packet of potato chip dispersed\n");
data->supply.potato_chips=data->supply.potato_chips-1;
data->transaction.potato_chips_sold=data->transaction.potato_chips_sold+1;
fprintf(io,"A packet of potato chips sold\n");
fprintf(io,"Amount enter:%.2f\n",&data->money.amount);
fprintf(pe,"Amount enter:%.2f\n",&data->money.amount);
fprintf(pe,"%d packet of potato chips sold\n",&data->transaction.potato_chips_sold);
}
else if (c>0.7)
{
printf("%.2f inserted\n", &data->money.amount);
printf("1 packet of potato chips dispersed\n");
data->supply.potato_chips=data->supply.biscuits-1;
data->transaction.potato_chips_sold=data->transaction.potato_chips_sold+1;
fprintf(io,"A packet of potato chips sold\n");
fprintf(io,"Amount enter:%.2f\n",&data->money.amount);
fprintf(io,"Amount enter:%.2f\n",&data->money.amount);
fprintf(pe,"%d packet of potato chips sold\n",&data->transaction.potato_chips_sold);
}
}
return;
}


PS: I have not finish writing the whole programe.

Please help me to figure out where did i go wrong. I have check thru and do not know where i have went wrong .
 
Status
Not open for further replies.
Back
Top Bottom