Purchase_details: printf("Details of the purchase..."); if(qty1>0){ gotoxy(6,4); printf("%s",prdnme1); gotoxy(26,4); printf("%f",unit_price1); gotoxy(43,4); printf("%d",qty1); gotoxy(60,4); subtotal1=unit_price1*qty1; printf("%f",subtotal1); } if(qty2>0){ gotoxy(6,6); printf("%s",prdnme2); gotoxy(26,6); printf("%f",unit_price2); gotoxy(43,6); printf("%d",qty2); gotoxy(60,6); subtotal2=unit_price2*qty2; printf("%f",subtotal2); } if(qty3>0){ gotoxy(6,8); printf("%s",prdnme3); gotoxy(26,8); printf("%f",unit_price3); gotoxy(43,8); printf("%d",qty3); gotoxy(60,8); printf("%f",unit_price3*qty3); }
It's me again.
I wanted to say, that your code was terrible. But it is not good to do so and do not explain, why.
So, your code was terrible. ;-)
Have a look, how it may be designed (use it as template):
#include "stdafx.h" #include"conio.h" #include"dos.h" struct ProductInfo { char Name[10]; int Qtty; float Prise; }; int ShowCurrentPurchaseDetails(ProductInfo onePurchase[]); int _tmain(int argc, _TCHAR* argv[]) { ProductInfo onePurchase[10] = {0,0,0,0,0,0,0,0,0,0}; cprintf("Welcome to D129 Store"); getch(); cprintf("\nYou're One-Stop Store.."); getch(); char ContinuePurchase = 'y'; int ii = 0; while (ContinuePurchase == 'y' && ii < 10) { printf("\nPlease encode the product you want to purchase : "); scanf("%s", &onePurchase[ii].Name); printf("Enter it's unit price : "); scanf("%f",&onePurchase[ii].Prise); printf("\nPlease encode the quantity you require : "); scanf("%d",&onePurchase[ii++].Qtty); ShowCurrentPurchaseDetails(onePurchase); printf("\nDo you want to continue? (Y/N)\n"); ContinuePurchase = getch(); } printf("\nThank You for shopping..."); printf("\nSee you again next time...."); getch(); } int ShowCurrentPurchaseDetails(ProductInfo onePurchase[]) { printf("\nDetails of the purchase..."); int ii = 0; float sum = 0; for (ii = 0; ii < 10; ii++) { if (onePurchase[ii].Qtty >0) { printf("\nName %s prise %f qtty %d",onePurchase[ii].Name, onePurchase[ii].Prise, onePurchase[ii].Qtty); sum += onePurchase[ii].Prise * onePurchase[ii].Qtty; } } printf("\ntotal sum now = "); printf("%f",sum); return 0; }
you can use yours gotoxy() and clrscr() instead "\n" (new line)
Thanks for this C coding practice. It was so nostalgically for me.
:-)
---deleted---
int _tmain(int argc, _TCHAR* argv[]) { printf("Details of the purchase..."); printf("\r\n"); printf("%s","erer"); printf("%f",6); printf("%d",6); printf("%f",6); printf("\r\n"); printf("%s","erer"); printf("%f",8); printf("%d",8); printf("%f",8); printf("\r\n"); printf("%s","erer"); printf("%f",9); printf("%d",9); printf("%f",9); printf("\r\n"); getchar(); return 0; }
printf("\r\n");