#include #include #include double str_flwt(char numberf[81]); int main(void) {//brmain int len81 = 81; char *my_string; int nbytes=88; double excesstot=0.0,score2=0.0,totexcess2=0.0,score3=0.0; printf("\n\n\tThis is a programme for a Benefice which wants to\n\ \tallocate its 'ministry share' among its churches\n\tin the\ same way that the diocese allocates\n\tthe 'ministry share'\ to the Benefices."); char *totword,*totprev; int x=0,punct=0; int newline=0; double yeartot; int slength=0; int year; char yyy = 'y'; int num=0,l=0; char *churches[81]; printf("\n\n\nEnter number of churches in your Benefice .. "); my_string = (char *) malloc (nbytes + 1); fgets(my_string, nbytes, stdin); sscanf (my_string,"%d", &num); char *ceachchurch[num+1]; char cop[num+1][31]; printf("\n\n"); double calc2[num+1]; double perc_change[num+1],calc[num+1],percperc[num+1],add25[num+1],excess2[num+1]; for(x=1;x<=num;x++) { printf(" Please input name of church No.%i ",x); churches[x] = (char *) malloc (nbytes + 1); fgets( churches[x], len81, stdin ); } double stats[num+1], previous, score=0.0, eachchurch[num+1], eachchurch25[num+1],excess[num+1]; double perc[num+1], newmin[num+1], maxp=0.0 ; double maxp2=0.0,perc2[num]; double ams[num+1],perchange[num+1],newams[num+1],newperc2[num+1]; int er[num+1],ec[num+1],t3[num+1],av[num+1]; printf("\n\n\n"); printf("Enter the year you wish to calculate the ministry share ... "); my_string = (char *) malloc (nbytes + 1); fgets(my_string, nbytes, stdin); sscanf (my_string,"%d", &year); printf("\nEnter the ministry share total for %i without 2%% discount ... ",year); totword = (char *) malloc (nbytes + 1); fgets(totword,len81,stdin); yeartot = str_flwt(totword); printf("\nEnter the ministry share total for %i without 2%% discount ... ",year-1); totprev = (char *) malloc (nbytes + 1); fgets(totprev,len81,stdin); previous = str_flwt(totprev); printf("\n\n"); printf("\nIn this section of the programme please be careful not to \n"); printf("input the letter 'o' when you meant to input the number '0' \n"); printf("-otherwise the programme will behave very strangely and you will\n"); printf("have to start from scratch again\n\n"); for(x=1;x<=num;x++) { printf(" For %s Enter electoral roll ...> ",*(churches+x)); my_string = (char *) malloc (nbytes + 1); fgets (my_string, nbytes, stdin); sscanf (my_string, "%d", &er[x]);} printf("\n\n"); for(x=1;x<=num;x++) { printf("For %s Enter easter communicants ...> ",*(churches+x)); my_string = (char *) malloc (nbytes + 1); fgets (my_string, nbytes, stdin); sscanf (my_string, "%d", &ec[x]);} printf("\n\n"); for(x=1;x<=num;x++) { printf("For %s Enter trinity 3 communicants ...> ",*(churches+x)); my_string = (char *) malloc (nbytes + 1); fgets (my_string, nbytes, stdin); sscanf (my_string, "%d", &t3[x]);} printf("\n\n"); for(x=1;x<=num;x++) { printf("For %s Enter average attendance ...> ",*(churches+x)); my_string = (char *) malloc (nbytes + 1); fgets (my_string, nbytes, stdin); sscanf (my_string, "%d", &av[x]);} printf("\n\n"); /* score total */ for(x=1;x<=num;x++) {stats[x] = ( av[x] + t3[x] + ec[x] + er[x] ) / 4.0; printf("\n%.4f\n",stats[x]); score = score + stats[x];} printf("\nscore total .. %.4f\n",score); printf("\nEnter ministry share each church paid in %d without 2%% discount\n",year -1); for(x=1;x<=num ;x++) { printf("for %s enter .............> ",*(churches+x)); ceachchurch[x] = (char *) malloc (nbytes + 1); fgets(ceachchurch[x],len81,stdin); eachchurch[x] = str_flwt(ceachchurch[x]); } printf("\n\n"); for(x=1;x<=num;x++) { newmin[x] = (yeartot * stats[x]) / score ; perc[x] = ((newmin[x] - eachchurch[x]) / eachchurch[x]) * 100.0 ; printf("\n[ %f .... %f ]",perc[x],newmin[x]); } for(x=1;x<=num;x++) { if (x == 1) { maxp = perc[x]; } if (maxp < perc[x]) { maxp = perc[x]; } } printf("\n\n\nmax percentage increase is ....%.2f%%\n",maxp); printf("\n\n"); if(maxp <= 25.0) {//br1 printf("The Totals below are without 2%% discount"); printf("\n\n"); for(x=1;x<=num;x++) { printf("For %sMinistry share total in %i is .. %.2f \n\n",*(churches+x),year,newmin[x]); } printf("\n\n"); printf("Percentage change for each church is ..\n"); for(x=1;x<=num;x++) { perc[x] = ((newmin[x] / eachchurch[x]) * 100.0) - 100.0; printf(" ...> %.2f%% change for %s",perc[x],*(churches+x)); } }//br1 // end of first part if(maxp > 25.00) {// maxp for(x=1;x<=num;x++) {//for loop1 if (perc[x] > 25.0) { eachchurch25[x] = eachchurch[x] * 1.25; excess[x] = newmin[x] - eachchurch25[x]; excesstot = excess[x] + excesstot; } if (perc[x] <= 25.0) { excess[x] = 0.0; score2 = stats[x] + score2; eachchurch25[x] = 0.000000; } }//for loop1 //ok for(x=1;x<=num;x++) { if (perc[x] <=25.0) { calc[x] = (stats[x] * excesstot) / score2; } } for(x=1; x<=num;x++) { if (perc[x] > 25.0) { ams[x] = eachchurch25[x]; } if (perc[x] <= 25.0) { ams[x] = calc[x] + newmin[x]; } } for(x=1; x<=num+1;x++) { perchange[x] = ((ams[x] - eachchurch[x]) / eachchurch[x]) * 100.0; } printf("\n____________________________________________________"); for(x=1;x<=num+1;x++) { printf(" \n SizeScore is %.2f for Church %s",stats[x],*(churches+x)); } printf("\n_____________________________________________________\n"); for(x=1;x<=num+1;x++) { printf(" \n MinShare is %.2f in %i for Church %s",newmin[x],year,*(churches+x)); } printf("\n_____________________________________________________\n"); for(x=1;x<=num+1;x++) { printf(" \n Percentage Change is %.2f for Church %s",perc_change[x],*(churches+x)); } printf("\n_____________________________________________________\n"); for(x=1;x<=num;x++) { printf(" \n Change for churches over 25%% is %.2f for Church %s",eachchurch25[x],*(churches+x)); } printf("\n_____________________________________________________\n"); for(x=1;x<=num+1;x++) { printf(" \n Excess is %.2f for Church %s",excess[x],*(churches+x)); } printf("\nTotal excess is ... %.2f ",excesstot); printf("\n_____________________________________________________\n"); for(x=1;x<=num+1;x++) { printf(" \n Additional Ministry Share payable is %.2f for Church %s",calc[x],*(churches+x)); } printf("\n_____________________________________________________\n"); for(x=1;x<=num+1;x++) { printf("\n Adjusted Ministry Share is %.2f in %i for Church %s",ams[x],year,*(churches+x)); } printf("\n_____________________________________________________\n"); for(x=1;x<=num+1;x++) { printf("\n Percentage change is %.2f for Church %s",perchange[x],*(churches+x)); } for(x=1;x<=num+1;x++) { if (x == 1) { maxp2 = perchange[x]; } if (maxp2 < perchange[x]) { maxp2 = perchange[x]; } } if (maxp2 <= 25.00) { printf("\n__________________________________________________________________\n"); for(x=1;x<=num+1;x++) { printf("\nMinistry Share is %.2f in %i for Church %s",ams[x],year,*(churches+x)); } printf("\n__________________________________________________________________\n"); } if (maxp2 > 25.00) {//maxp2 for(x=1;x<=num+1;x++) {//for loop if (perchange[x] <=25.0) { add25[x] = ams[x]; } if (perchange[x] > 25.0) { add25[x] = eachchurch[x] * 1.25; } }//for loop printf("\n===++++++++++++++++++++++++=========+++++++++++++\n\n"); for(x=1;x<=num+1;x++) { printf("25%% change for churches over 25%% is %.2f for Church %s",add25[x],*(churches+x)); } printf("\n===++++++++++++++++++++++++=========+++++++++++++\n\n"); for(x=1;x<=num+1;x++) { excess2[x] = ams[x] - add25[x]; totexcess2 = excess2[x] + totexcess2; } for(x=1;x<=num+1;x++) { printf("excess is %.2f for Church %s",excess2[x],*(churches+x)); } printf("\ntotal excess is ... %.2f\n",totexcess2); printf("\n===++++++++++++++++++++++++=========+++++++++++++\n\n"); for(x=1;x<=num+1;x++) { if (perchange[x] < 25.0) { score3 = stats[x] + score3; } } for(x=1;x<=num+1;x++) {//for loop if (perchange[x] <= 24.9999) { calc2[x] = (stats[x] * totexcess2) / score3; } if (perchange[x] >= 25.0) { calc2[x] = 0.0; } }// for loop for(x=1;x<=num+1;x++) { printf("Additional ministry share payable is %.2f for Church %s",calc2[x],*(churches+x)); } printf("\n===++++++++++++++++++++++++=========+++++++++++++\n\n"); for(x=1;x<=num+1;x++) { newams[x] = add25[x] + calc2[x]; } for(x=1;x<=num+1;x++) { printf("New adjusted ministry share is %.2f for Church %s",newams[x],*(churches+x)); } printf("\n===++++++++++++++++++++++++=========+++++++++++++\n\n"); for(x=1;x<=num+1;x++) { newperc2[x] = ((newams[x] - eachchurch[x]) / eachchurch[x]) * 100.00 ; } for(x=1;x<=num+1;x++) { printf("New percentage change is %.2f for Church %s",newperc2[x],*(churches+x)); } printf("\n===++++++++++++++++++++++++=========+++++++++++++\n\n"); for(x=1;x<=num+1;x++) printf("Ministry Share is %.2f in %i for Church %s",newams[x],year,*(churches+x)); }//maxp2 }// maxp printf("\n\nFinish\n\n"); while(len81==81) {totword = (char *) malloc (nbytes + 1); fgets(totword,len81,stdin);} return 0; }//brmain double str_flwt(char numberf[81]) { char copy[81]; int slength=0; int x =0; int punct = 0; int stringl = 81; int bytes =81; if (numberf != "\n" ) {strcpy(copy,numberf);} slength = strlen(copy); for(x=0;x<=slength;x++) {//for if((ispunct(copy[x]) && copy[x] == ',') || copy[x] == ' ')//checks for comma or space in number { //////// printf("\nyou have entered a comma or space in this number"); printf("\nPlease input number again.... "); fgets(numberf,stringl,stdin); if (numberf != "\n" ) {strcpy(copy,numberf);} x =-1; slength = strlen(copy); }//////// if((copy[x]) == '.') //checks for 2 decimal points. {//// punct = punct + 1; if(punct >=2) {printf("\nyou have entered a couple of punctuation characters in this number"); printf("\nPlease input number again.... "); fgets(numberf,stringl,stdin); if (numberf != "\n" ) {strcpy(copy,numberf);} punct = 0,x=-1; slength = strlen(copy); } }//// if(isalpha(copy[x])) // checks for alphabet letter {printf("\nyou have entered a letter"); printf("\nPlease input number again.... "); fgets(numberf,stringl,stdin); if (numberf != "\n" ) {strcpy(copy,numberf);} slength = strlen(copy); x = -1; } if((ispunct(copy[x]) && copy[x] != '.')) //checks for punctuation character { //////// printf("\nyou have entered punctuation"); printf("\nPlease input number again.... "); fgets(numberf,stringl,stdin); if (numberf != "\n" ) {strcpy(copy,numberf);} x =-1; slength = strlen(copy); }//////// }//for double numberf2; char *p; numberf2 = strtod(copy,&p);//converts string to double number return(numberf2); }