Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //short artishok with functions, some questions
- //1. why Pay attention prints, even when first in input is alpha? check in main()
- //2. how make while ... a, b, c, q more compact?
- //
- char get_char(void);
- float get_float (void);
- int main()
- {
- char ch;
- float fl;
- while((ch =get_char())!='q')
- {
- printf("%c\n",ch);//print proper input,rid of user mistakes
- fl= get_float();
- printf("%f\n",fl);
- }
- return 0;
- }
- char get_char(void)
- {//input:38kn... - get rid of everything
- // kn... takes k, get rid of everything else
- // k takes k
- char c;
- printf("Chose a,b,c or q?\n");
- while((c=getchar())!= 'a' && c!='b' && c!='c' &&c!='q')
- // while(!isalpha(c=getchar())) //while first symbol in input is not alpha
- {
- //printf("Pay attention, you suppose to input a,b,c or q\n");
- }
- while(getchar()!='\n') //rid of rest of input, including '\n'
- continue;
- return c;
- }//end of get_char
- float get_float(void)//this one is ok
- {
- 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