Hi,
The following program works fine if an int is declared instead of the short int for tracks ,but if I do declare /*tracks*\ as a short int then whilst giving the output
it does not print out the name of the artist.But then again if I do declare tracks as a short int before the strings the output is fine and the program prints out the name of the artist as well.All I know is you will have to declare the variable you are planning to use at the start of the program ,Is it necessary that short int has to be declared before the strings.Here is the code I am trying to run
Code:
/* cd inventory*/
#include<stdio.h>
int main()
{
char title[61];
char artist[61];
short int tracks;/* if short int is declared at the top the program runs fine else the
program runs fine if tracks are declared as int rather than short int here*/
float price;
int album;
char type;
printf("Welcome to the cd database\n");
printf("====================================================\n");
/* scanning the title of the track*/
printf("Please enter the title:");
scanf("%[^\n]",title);
fflush(stdin);
/* scanning the artist name */
printf("\nPlease enter the name of the artist:");
scanf("%[^\n]",artist);
fflush(stdin);
/* scanning the number of tracks*/
printf("\nPlease enter the number of tracks:");
scanf("%d",&tracks);
fflush(stdin);
/* checking if single or complete album*/
printf("\nPlease enter 'a' if album 's' if single:");
scanf("%c",&type);
fflush(stdin);
album=type=='a';/* if anything other than a is entered it assumes as s*/
/* scanning the price of the album or single*/
printf("\nPlease enter the price:");
scanf("%f",&price);
fflush(stdin);
/*Printing the output from the database*/
printf("The cd details you entered are\n");
printf("======================================================\n");
printf("Title:%s\n",title);
printf("Arist:%s\n",artist);
printf("Number of tracks:%d\n",tracks);
if (album)
printf("Album\n");
else
printf("Single\n");
printf("Price :%.2f\n",price);
printf("=======================================================\n");
printf("Press the enter key to exit");
getchar();
}