C: Can't seem to find the bug [Do-While loop] -


The program is simple:

1) It accepts the user's name 2) Bought and How much does it cost 3) If there are some items> 10 items, then it says, "Enter more than 0 (zero) number and less than 10 (ten) number. Do you want to continue building another bill? (Y / N) "4) User Input 'Y' should start and start at the beginning of the Duplicate loop.

Everything is working fine in the middle. Here is the code:

  int main () {four items [10] [10], answer = 'null', name [10]; Int price [10], total_itim, total_price = 0, i, j = 0, a; Float service_tex = 0, brick = 0, total_bill = 0, bill = 0; Printf ("Please enter your name:"); Scanf ("% s", name); {Printf ("\ nEnter the total items purchased (must be greater than 0 and less than 10):"); scans ("% d", & amp; total_item); if (total_item & Gt; 0 & amp; amp; amp; total_item & lt; = 10) {for (i = 0; i & lt; total_item; i ++) {printf ("Enter \ n item name:"); scanf "% S", item [i]); Printf ("Enter the \ n item price:"); scanf ("% d", and value [i]); bill = bill + value [i];} printf ("You have the bill without tax:% f \ (" Bill * 10) / 100); VAT = ((* Bill * 12) / 100); Total_bill = Service_tex + VAT + Bill; Print ("purchased by you Items are: \ "N"); (i = 0; i & lt; total_item; i ++) {printf Printf ("your total bill is:% 3f", total_bill); printf ("Your bill #% s-% D-% d ", and the name, total_item, rand ()% 1000);} Other {printf (" \ n% s, please enter more than 0 (zero) and less than 10 (ten) " , & Amp; Name); Printf ("\ nDo you want to continue building another bill (Y / N) \ n"); Scanf ("% c", and answer);}} while ((Answer == 'Y') || (Answer = 'Y')); Return 0;}  

Please help me!

Your help is greatly appreciated!

this:

  while ((reply == 'Y' ) || (Answer = 'Y')); When using   

= , it means == . The above condition will always be correct, because 'y' is not zero.

Some people always stop this problem by typing variables on their right hand, i.e. will be written as the above (true)

  while (('y' == Answer) || ('Y' == Answer));  

is written like this, if you miss a = , you get an error because the text on the left is not literally assigned.

I dislike it, I find it hard to read. It breaks even when comparing two variables, which is not uncommon.


Comments