Hi everyone,
I'm new to the forums and having a problem that I can't seem to fix, so it would be great if someone could help me out!
Everything in the following code works except for the while loop. When it gets to the "Input another product? (y/n) :" line, no matter what letter I enter it will not loop back to the beginning. It just displays the next part with the grand totals. Please help! Thanks!
/* ================================================================== */
/* > Program: intmenu2.c < */
/* > < */
/* > Description: printf, scanf, loop < */
/* > < */
/* > Name Date Comment < */
/* > ------------- -------- ------------------------------ < */
/* > 2/07/08 Author < */
/* ================================================================== */
#include <stdio.h>
#include <stdlib.h>
int main()
{
int prodnum, prodtype, prodquan, count = 0;
double cost = 0, price = 0, total = 0;
double prod_cost = 0, prod_price = 0, prod_profit = 0;
double total_price = 0, total_cost = 0, total_profit = 0;
char choice;
system("cls");
do
{
printf("Sierra Sporting Goods\n\n");
printf("Enter the product number: ");
scanf("%d%*c", &prodnum);
printf("Enter the product type: ");
scanf("%d%*c", &prodtype);
printf("Enter the quantity: ");
scanf("%d%*c", &prodquan);
count++;
printf("Enter the unit cost: ");
scanf("%lf", &cost);
printf("Enter the unit price: ");
scanf("%lf", &price);
prod_price = price * prodquan;
prod_cost = cost * prodquan;
prod_profit = (price - cost) * prodquan;
total_price += prod_price;
total_cost += prod_cost;
total_profit += prod_profit;
printf("\n\n\n");
printf("Sierra Sporting Goods\n\n");
printf("The product number is ----> %04d\n", prodnum);
printf("The product type is ------> %d\n", prodtype);
printf("The quantity is ----------> %d\n", prodquan);
printf("The cost is --------------> %.2lf\n", cost);
printf("The price is -------------> %.2lf\n\n", price);
printf("Total product price ------> %.2lf\n", prod_price);
printf("Total product cost -------> %.2lf\n", prod_cost);
printf("Total product profit -----> %.2lf\n\n", prod_profit);
printf("Input another product? (Y/N): ");
scanf("%c%*c", &choice);
}
while (choice == 'y' || choice == 'Y');
printf("\n\n");
printf("Total count of products --> %d\n", count);
printf("Total all prices ---------> %.2lf\n", total_price);
printf("Total all costs ----------> %.2lf\n", total_cost);
printf("Total profit -------------> %.2lf\n", total_profit);
printf("\n\n");
return 0;
}