Basic Code not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Metalman
    New Member
    • Apr 2012
    • 5

    Basic Code not working

    So what I am trying to do is write a simple program with a main menu where the user will be able to fill in the details of a project,list all projects, delete a chosen project or exit the program. Projects will be saved in an array. The functions will use structures.

    I have written a functional code which compiles fine(big deal lol i know) but thus far only the 4th option "exit" works. The other 3 choices seem to not be working.

    Here's my code

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    #include <string.h>
    
    struct fullname
    {
            char name[10];
            char surname[10];
    };
    struct meletes
    {
            int identifier;
            struct fullname customer;
            char date[10];
            float price;
    };
    void initialize(struct meletes projects[10]);
    struct meletes newp(struct meletes projects[10]);
    struct meletes list(struct meletes projects[10]);
    struct meletes deletep(struct meletes projects[10]);
    
    int main(void)
    {
    int choice,k;
    struct meletes projects[10];
    
    void initialize(struct meletes projects[10]);
    
    printf("Main Menu\n ========\n");
    printf("Please choose a function from below:\n");
    printf("1.New Project\n2.Delete\n3.List\n4.Exit\n");
    scanf("%d", &choice);
    
        while ((choice != 1) && (choice != 2) && (choice != 3) && (choice != 4))
              {
               
               printf("You have chosen a wrong function, please use numbers 1-4:\n\n");
               printf("Main Menu\n ========\n");
               printf("Please choose a function from below:\n");
               printf("1.New Project\n2.Delete\n3.List\n4.Exit\n");
               scanf("%d", &choice);
               }
    
              while (choice != 4)
              {
              switch (choice) {
              
                     case 1:
                     {
                      struct meletes newp(struct meletes projects[10]);
                             
                      }
                      
                     case 2:
                     {
                      struct meletes deletep(struct meletes projects[10]);
                       
                      }
                          
                     case 3:
                     {
                      struct meletes list(struct meletes projects[10]);
                           
                     }
                             }
                             
               
                printf("Main Menu\n ========\n");
                printf("Please choose a function from below:\n");
                printf("1.New Project\n2.Delete\n3.List\n4.Exit\n");
                scanf("%d", &choice);             
                                     
              }        
                          
              printf("Thank u.\n");
              
    system("pause");
    return 0;
    }
    
    void initialize(struct meletes projects[10])
    {
    int l;
     for(l=0; l<10; l++)
      {
              projects[l].identifier = 00000;
              projects[l].price = 0.00;
              strcpy(projects[l].customer.name,"----------");
              strcpy(projects[l].customer.surname,"----------");
              strcpy(projects[l].date, "0/0/0");
      }          
    }          
    
    struct meletes newp(struct meletes projects[10])
    {
            int i;
            for(i=0; i<10; i++)
            {
                     if (projects[i].identifier == 00000)
                     {
                        scanf("Please enter the project's identifier %d\n", &projects[i].identifier);
                        scanf("Name:%s\n", &projects[i].customer.name);
                        scanf("Surname:%s\n", &projects[i].customer.surname);
                        scanf("Give the date in dd/mm/yyyy! format :%c\n", &projects[i].date);
                        scanf("Price:&f\n", &projects[i].price);
                     }
                 break;
            }                
            
    }
    
    struct meletes deletep(struct meletes projects[10])
    {
           int j,id;
            for (j=0; j<10; j++)
            {
                if (projects[j].identifier != 00000)     //Emfanizei oles tis meletes pou den ine diegrammenes
                   {
                   printf("%d\n", projects[j].identifier);
                   }
            }
            
            scanf("\nPlease insert the identifier of the project u want to delete:%d", &id);
            
            for(j=0; j<10; j++)
            {                       
              projects[j].identifier = 00000;
              projects[j].price = 0.00;
              strcpy(projects[j].customer.name,"----------");
              strcpy(projects[j].customer.surname,"----------");
              strcpy(projects[j].date, "0/0/0");
            }
            
    }
            
    struct meletes list(struct meletes projects[10])
    {
           int k;
            for(k=0; k<10; k++)
            {
                     if (projects[k].identifier != 00000); 
                        {
                        printf("         Project %d:", k);
                        printf("\nIdentifier:%d\n", projects[k].identifier);
                        printf("Name:%s\n", projects[k].customer.name);
                        printf("Surname:%s\n",projects[k].customer.surname);
                        printf("Date:%s\n", projects[k].date);
                        printf("Price:%d\n", projects[k].price);
                        }
            }
    
    }
    Any ideas will be really appreciated
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    It looks like you are missing break statements at the end of each of the cases in your switch.

    There may be other stuff but I didn't look that far.

    Comment

    Working...