My newest code is here....I could now display customer search result but, when the customer input search 2 cd at the same time then input 2 cd names, the result only display 1 cd info. How can I display 2 cd info after customer input 2 cd names?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct CD {
char group_name[49];
char cd_name[49];
int year;
double price;
double playing_time;
} Collection;
int main(void){
Collection digimon[3] = {
{"Digimon","Digimon", 1999, 25.5, 25.5 },
{"Pokemon","Pokemon", 1999, 25.5, 25.5 },
{"Dragon","Dragon", 1999, 25.5, 25.5 }
};
int i, found, cd_qty;
char req_group[50];
printf("\n\nHow many cd you wish to search? ");
scanf("%d",&cd_qty);
fflush(stdin);
for(i=0;i<cd_qty;i++){
printf("\nName of the cd? ");
gets(req_group);
}
found = 0;
cd_qty = 50;
for(i=0;i<cd_qty;i++){
if(strcmp(digimon[i].group_name, req_group) == 0) {
// we found it
found = 1;
break;
}
}
if (found == 1)
{
printf("I found what you wanted!\n");
printf("Group Name: %s\nCD Name: %s\nYear: %d\nPrice: %.2lf\nPlaying Time: %.2lf",
digimon[i].group_name, digimon[i].cd_name, digimon[i].year, digimon[i].price, digimon[i].playing_time);
}
else
{
printf("Sorry, I couldn't find it.\n");
}
return 0;
}