Mã:
#include <stdio.h>#include <conio.h>#include<string.h> struct Book{ char ISBN[10]; float price; float value; int quantity; }; int i=0,dem=0;float total=0;char c;Book tg;Book sach[100];void input(){ while(1) { while(1) { fflush(stdin); printf("ISBN : "); float ch= scanf("%s%c",&sach[i].ISBN,&c); if(ch==0 || c!='
' || sach[i].ISBN<0) printf("
Input incorrect.
"); else break; } if (sach[i].ISBN ==0) break; //câu này nó không chiu chay. else { while(1) { fflush(stdin); printf("Price : "); float ch= scanf("%f%c",&sach[i].price,&c); if(ch==0 || c!='
' || sach[i].price<0) printf("
Input incorrect.
"); else break; } while(1) { fflush(stdin); printf("Quantity : "); int ch= scanf("%d%c",&sach[i].quantity,&c); if(ch==0 || c!='
' || sach[i].quantity<0) printf("
Input incorrect.
"); else break; } sach[i].value=sach[i].price*sach[i].quantity; total =total + sach[i].value; } i++; dem++; } }void sort(){ for (int i = 0; i < dem-1; i++) for (int j = i + 1; j < dem; j++) if (strcmp(sach[i].ISBN, sach[j].ISBN) > 0){ char tmp[11]; strcpy(tmp, sach[i].ISBN); strcpy(sach[i].ISBN, sach[j].ISBN); strcpy(sach[j].ISBN, tmp); }}void output(){ sort(); printf(" Book in tock.
"); printf(" =====================
"); printf("ISBN Price Quantity Value
"); printf("-----------------------------------------------
"); for(i=0; i<dem;i++) { printf("%s ",sach[i].ISBN); printf("%.2f ",sach[i].price); printf("%d ",sach[i].quantity); printf("%.2f
",sach[i].value); } printf(" ___________
"); printf("Total value books in stock %.3f",total);} main(){ while(1) { printf(" Books in Stock Organizer
"); printf(" ========================
"); input(); output(); char choice; printf("
"); fflush(stdin); printf("Another run (y)?:"); scanf("%c",&choice); if(choice=='y') { printf("Again."); } else { printf("Good bye!"); return(choice); break; } } getch();}
View more random threads:
Trứng rung điều khiển từ xa Vibrator Spark Of Love Sản phẩm trứng rung bluetooth có điều khiển từ xa này được thiết kế với tông màu Rose Gold viền kim khí trải qua. kích tấc 7,4cm x 3,5cm giúp trứng...
TOP 3 trùy rung điều khiển từ xa...