Code:
//
/* Course_Project.c
*
* Program to maintain a database of CDs for a record store.
* This is the Course Project for the C Programming Course
*
*
* by snidely whiplash, 2006.
*/
//
#include <stdio.h>
#include <ctype.h>
main()
{
char title[100][61];
char artist[100][61];
int tracks[100]; /* number of tracks on the CD */
char type; /* used to read in album/single info */
int album[100]; /* boolean - is the CD an ALBUM? */
float price[100];
int i, j;
int records = 0;
int count = 0;
printf("Welcome to the CD database.\n\n");
printf("How many CDs do you want to enter? ");
fflush(stdin);
scanf("%d", &records);
printf("\nPlease enter the details of the CD...\n");
for (i = 0; i < records; i++)
{
/*Get the artist*/
printf("Artist? ");
fflush(stdin); /*this means to flush anything from...*/
scanf("%[^\n]", artist[count]); /*The [^\n] means "read...*/
/*Get the title*/
printf("Title? ");
fflush(stdin);
scanf("%[^\n]", title[count]); /*must use the [^\n]...*/
/*Get the number of tracks*/
printf("Number of tracks? ");
fflush(stdin);
scanf("%d", &tracks[count]); /*Need the '&' now...*/
if (isdigit(tracks[count]))
/*else
printf("Error!\n");*/
/*Is this an Album (a) or Single (s)?*/
for ( ; ; ) /*forever loop--continues until the user...*/
{
printf("Album or single ('a' for album, 's' for single)? ");
fflush(stdin);
scanf("%c", &type);
if (type == 'a' || type == 's') /* If type == 'a' or type...*/
break;
else
printf("Error!\n");
}
album[count] = type == 'a';
/*Get the price*/
printf("Retail price (e.g. 4.65)? ");
fflush(stdin);
scanf("%f", &price);
/*increment the counter for the record count*/
count = count + 1;
}
/*Output the CD details*/
for (i = 0; i < count; i++)
{
printf("\nThe CD details you entered are:\n");
printf("==============================\n");
printf("Artist: %s\n", artist[i]);
printf("Title: %s\n", title[i]);
printf("Number of tracks: %d\n", tracks[i]);
if (album[i])
printf("Album\n");
else
printf("Single\n");
printf("Price: %.2f\n", price[i]); /*Print the price with two decimal places*/
printf("The value of 'i' is: %d\n", i);
printf("==============================\n");
}
/*A user-friendly exit of the program*/
printf("\nPress ENTER to exit the program: ");
fflush(stdin);
getchar();
}
This is one of the programs I have been working on for the CD course in C I have been learning from. But it does not compile for me with the '//' in the file header; though it did with the '/*...*/'
But I did not use a console application to create it. After reading your post, I *did* try to open a console application and try to compile with the C++ commenting symbols...and it worked. But why?
Thanks for the help.
TCB