While loop not skipping when condition isn't met
Code:
#include <stdio.h>
void calc_duty(int, float, float, float *, float *);
void print_duty(int, int, int, float, float, float, float);
int main (void)
{
int origin, category, quantity;
float price, ship_price, duty;
float tax;
char looping;
printf("Do you have more customs form to process(type: Y for yes, N for no)?\n");
scanf("%c",&looping);
while ((looping != 'Y') && (looping != 'N'))
{
printf("You have to enter Y for Yes or N for No. Please try again. \n");
/* Discard the end of line character or other characters */
scanf("%c",&looping);
}
while ((looping = 'Y'))
{
printf("What is the origin of the goods (type: 1 for US, 2 for China, and 3 for Brazil)?\n");
scanf("%d", &origin);
printf("What category of goods (type: 1 for food, 2 for clothing, and 3 for wood)?\n");
scanf("%d", &category);
printf("What quantity of goods?\n");
scanf("%d", &quantity);
printf("What is the unit price?\n");
scanf("%f", &price);
if (origin=1)
{
if (category=1)
{
tax=0.00;
}
if (category=2)
{
tax=0.00;
}
if (category=3)
{
tax=0.05;
}
}
if (origin=2)
{
if (category=1)
{
tax=0.02;
}
if (category=2)
{
tax=0.03;
}
if (category=3)
{
tax=0.04;
}
}
if (origin=3)
{
if (category=1)
{
tax=0.01;
}
if (category=2)
{
tax=0.02;
}
if (category=3)
{
tax=0.08;
}
}
calc_duty(quantity, price, tax, &ship_price, &duty);
print_duty(origin, category, quantity, price, tax, ship_price, duty);
printf("Do you have more customs form to process(type: Y for yes, N for no)?\n");
scanf("%c", &looping);
while ((looping != 'Y') && (looping != 'N'))
{
printf("You have to enter Y for Yes or N for No. Please try again. \n");
/* Discard the end of line character or other characters */
scanf("%c",&looping);
}
}
printf("You have exited the loop.\n");
}
void calc_duty(int quantity, float price, float tax, float *ship_price, float *duty)
{
*ship_price=quantity*price;
*duty=*ship_price*tax;
}
void print_duty(int origin, int category, int quantity, float price, float tax, float ship_price, float duty)
{
printf("Origin Category Quantity Unit Price Shipment Tax Rate Duty\n");
printf("%d %d %d %0.02f %0.02f %0.02f %0.02f ", origin, category, quantity, price, tax, ship_price, duty);
}
For some reason when I get to:
Code:
printf("Do you have more customs form to process(type: Y for yes, N for no)?\n");
and put N it doesn't skip my while loop even though the condition is that looping=Y
Edit: Just to clarify; the loop that checks if looping isn't equal to Y or N works. The larger loop is the one that doesn't.