Public feed #527467

Miscellany

public c v1 · immutable
Raw Edit
·published 2007-06-01 09:53 UTC
rendered paste body
#include <stdio.h>main(){      char   artist[71];      char   title[71];      int    numtracks;      char   type;      int    album;      float  price;      printf("Welcome to the CD Database\n");       printf("\n");    {      printf("Enter the title of the CD: ");        scanf("%[^\n]", title);    } printf("\n");       fflush(stdin);      {        printf("Enter the artist name: ");          scanf("%[^\n]", artist);      } printf("\n");         fflush(stdin);         /* I am having trouble with the "else goto proceed;" part of the code, the compiler            seems to think there is a parse error before 'else'. When I remove 'else' altogether            it compiles correctly. I basically need a way to proceed with the code instead of            having to resort to 2 goto statements, otherwise it loops the first bit of code forever            even if i input a value that is less than 21.*/enteragain:          {            printf("Enter the number of tracks on the CD: ");              scanf("%d", &numtracks);              {                if (numtracks > 21)                   printf("\nInvalid answer!\n");                   printf("\n");                 goto enteragain;                else                   goto proceed;              }          } printf("\n");             fflush(stdin);proceed:         {           printf("Is the CD an album or a single? (a for album, s for single): ");              scanf("%c", &type);              album = type == 'a';         } printf("\n");            fflush(stdin);        {           printf("Enter the retail price of the CD: $");             scanf("%f", &price);        }  printf("\n");            fflush(stdin);           {             printf("\n---------------------------------------\n");             printf("The details of your CD\n");             printf("---------------------------------------\n");           }             {               printf("Title : %s\n", title);               printf("Artist Name : %s\n", artist);               printf("Number of tracks : %d\n", numtracks);             }               {                  if(album)                    printf("Album\n");                    else                      printf("Single\n");               }        {           printf("Price : $%.2f\n", price);           printf("---------------------------------------\n");          printf("Press ENTER at any time to exit\n");          printf("---------------------------------------\n");        }       fflush(stdin);      getchar();}