Credits

Thursday, February 19, 2009

Loops in Sales

Below is another sample program in C. This program is expected to read an item, its code, quantity, unit price and compute the needed charge and change from the cash given.



[+/-] show/hide



#include stdio.h /*enclose stdio.h with <> */
main()
{char item[20],itemcode[5],option;
float quantity,total,unitprice,
charge,cash,change;

clrscr();
total=0.0;

do
{
printf("\nInput an item code:");
scanf("%s",&itemcode);
printf("\ninput item description:");
scanf("%s",&item);
printf("\ninput quantity:");scanf("%f",&quantity);
printf("\ninput unit price:");scanf("%f",&unitprice);
charge=quantity * unitprice;
total=charge+total;
printf("\nInput item again [y/n]?");
option=getch();
}
while (option=='Y' || option=='y');

printf("\nYOur total charge : %.2f",total);
printf("\ninput your cash");
scanf("%f",&cash);
change=cash-total;
printf("Your change:%.2f",change);
getch();
}

Translate this in Bloodshed C++.

AddThis