My program asks the user to input sold and price. both are floting point number. they use the same function for validation. the function checks the input data which must be 0-9 and/or "."
i use "pass" for checking true or false. it is supposed to send the value of "pass" to the main but it isn't
how can i fix this problem?
Thanks
Code:#include <stdio.h> #include<string.h> #include<stdlib.h> void check(struct Sell s,char amoun[50]); struct Sell { float amountsold,retailprice; bool pass; }; //******************M a i n************* int main (void) { struct Sell st; bool k=true; char amountsol[50],retailprice[50]; int e,len,i; st.pass=true; do { do { puts("Enter amount sold: "); gets(amountsol); check(st,amountsol); printf("Pass Main:%d\n",st.pass); }while(!st.pass); st.amountsold=atof(amountsol); printf("Amoundsold :%f\n",st.amountsold); do { puts("Enter retailprice: "); gets(retailprice); check(st,retailprice); printf("Pass Main :%d\n",st.pass); }while(!st.pass); st.retailprice=atof(retailprice); } while(!st.pass); printf("Amountsold :%f \n",st.amountsold); printf("amountinFunct: %f\n",st.retailprice); } //**********f u n c t i o n ******************** void check(struct Sell s,char num[50]) { int e,len,i,n; len=strlen(num); for (e=0;e<len;e++) { switch (num[e]) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : case '.' : s.pass=true; printf("Pass Funct:%d\n",s.pass); break; default : s.pass=false; printf("Pass Funct:%d\n",s.pass); puts(" Amount sold error \n"); break; } } printf("Pass in Function before return :%d\n",s.pass); return(s.pass); }



LinkBack URL
About LinkBacks



P