Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //broken now, once I've done it with functions!
- //from step 2, char choice working second time only, not first time!
- //something EXTRA in bufer or some other place messes up with everything!
- //2 really basic functions,only to make sure,3that user didn't mess up, and input
- //char and float where he suppose to do so
- //without checking user's input it will be 6 or so lines long programm
- //
- char get_char(void);
- float get_float (void);
- int main()
- {
- char ch;
- float fl;
- while((ch=get_char())!='q')
- {
- printf("in main %c\n",ch);
- fl = get_float();
- printf("in main %f\n",fl);
- }
- return 0;
- }
- char get_char(void)
- {//input:38cn... - get rid of everything
- // cn... takes c, get rid of everything else
- // c takes c, get rid of new line
- char c;
- printf("in func:Chose a,b,c or q?\n");
- while((c=getchar())!= 'a' && c!='b' && c!='c' && c!='q')
- {
- while(getchar()!='\n') //when input is wrong
- continue;
- // printf("in func:Attention,input a,b,c
- }
- while(getchar()!='\n') //when input is right
- continue;
- return c;
- }//end of get_char
- float get_float(void)
- {
- float amount;
- int sc_res =0;
- do
- {
- printf("how much of it do you want?\n");
- sc_res = scanf("%f",&amount);
- if(!sc_res)
- scanf("%*s");
- }while(!sc_res);
- return amount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement