c - How to use For loop with char? -
by using loop. want let user input amount of lemonade want order. program calculate tax, subtotal, , total. after should let them continue either entering 'y' or 'n'.
when compile these codes. blanks. wrong codes?
so made changes. don't know how have stop program if enter 'n' if ask continue.
#define _crt_secure_no_warnings #include<stdio.h> #include<stdlib.h> void main() { int numcups; float subtot, tot = 0, tax; char more; printf("enter number of cups:"); scanf("%d", &numcups); subtot = numcups*1.29; tax = subtot*0.0825; tot = subtot + tax; printf("subtotal:%0.2f\ntax:%0.2f\ntotal:%0.2f\n", subtot, tax, tot); fflush(stdin); printf("thank you.\nwould order more lemonade?\n"); (; scanf("%c", &more);) { printf("enter number of cups:"); scanf("%d", &numcups); subtot = numcups*1.29; tax = subtot*0.0825; tot += subtot + tax; fflush(stdin); printf("subtotal:%0.2f\ntax:%0.2f\ntotal:%0.2f\n", subtot, tax, tot); printf("thank you.\nwould order more lemonade?\n"); } system("pause"); }
try this:
(; scanf("%c", &more)&&more=='y';) this change let continue when use y character.
Comments
Post a Comment