Hi everyone. I've been struggling a bit with some code using unions and structures. Right now, I'm just trying to get the following code to work the way I want it too. The way it SHOULD work is prompt the user for the type of record they want to enter...either 'b' for book or 'm' for CD. It will then go into the appropriate list of what needs to be enter for that record and place that information into an array....It needs to do other stuff also, but I think I can manage it....At least I think so. Anyways, here is the code that I have written...It does compile and run...But not the way I want it to. Any help or suggestions are greatly appreciated.
Code:
#include<stdio.h> 

struct book 
{
char name[30];
char title[30]; 
char publisher[30]; 
char year[4]; 
float price; 
char code[8];
};

struct cd
{
char ComposerName[25];
char CDTitle[35]; 
char interpr[40]; 
char Publishedyear[4]; 
float CDPrice; 
char CatCode[8]; 
};

struct book booklist[3]; 
struct cd CDlist[3]; 

int main(){ 
char ch;
int i;

printf("Please enter 'b' if you want to add a book record or 'm' to enter a CD record: "); 
	ch = getche();
	if (ch = 'b')
	{ 
                for(i=0;i<3;i++)
	{ 
	printf("Enter author's name: "); 
	scanf("%s", booklist[i].name); 

	printf("Enter the book title: "); 
	scanf("%s\n", booklist[i].title); 

	printf("Enter the publisher: "); 
	scanf("%s\n", booklist[i].publisher); 

	printf("Enter the year: "); 
	scanf("%s\n", booklist[i].year); 

	printf("Enter the price: "); 
	scanf("%d\n", booklist[i].price); 

	printf("Enter the book code: "); 
	scanf("%s\n", booklist[i].code);
	} 
	}

	if (ch = 'm')
	{
	for(i=0;i<3;i++)
	{ 
	printf("Enter composer's name: "); 
	scanf("%s", CDlist[i].ComposerName); 

	printf("Enter the CD title: "); 
	scanf("%s\n", CDlist[i].CDTitle); 

	printf("Enter the interpreter(s): "); 
	scanf("%s\n", CDlist[i].interpr); 

	printf("Enter the year it was published: "); 
	scanf("%s\n", CDlist[i].Publishedyear); 

	printf("Enter the price of the CD: "); 
	scanf("%d\n", CDlist[i].CDPrice); 

	printf("Enter the catalog code: "); 
	scanf("%s\n", CDlist[i].CatCode);
			
	} 
	}

}
Read this before posting code
http://www.cprogramming.com/cboard/m...bbcode#buttons