I am trying to run a program using this while loop function. It's just a simple code with the loop function.But the problem is, the first part is running correctly the second part is not responding correctly. It's just calculating a purchase by entering price & the quantity and it should give us the total of those purchase by multiplying price with the quantity after that it supposed to as for another purchase, and the problem starting with this part. it's not really asking for the second purchase it just jumped to the last part.
Since I'm new to this type of community your help will be a great thing for me. (I'm learning C myself)
#include <stdio.h>
int main(void)
{
float price;
short quantity;
char answer;
printf("So you wish to enter a purchase?(Y/N)? ");
scanf("%c", &answer);
while(answer== 'Y' || answer== 'y')
{
printf("Enter 'price & quantity': ");
scanf("%f %hi", &price, &quantity);
printf("The total for this item is $%6.2f.\n", price * quantity);
while(answer == 'Y' || answer == 'y')
printf("Another purchase(Y/N)? "); //problem with this part
scanf("%c", &answer);
}
printf("\nThank you for your patronage.\n");
getchar();
return 0;
}

New Topic/Question
Reply




MultiQuote





|