0

I'm very new to C programming and I'm trying to create a simple task management system. But this code doesn't run and it doesn't show me what the error is too. Am I doing something wrong with the functions? This part of the code is just me trying to get a choice from the user and then divert them to different functions according to their choice.

#include<stdio.h>

void add_task(void);
void view_task(void);
void manage_task(void);

int main()
{
    void main_menu(void);
    char main_choice;
    printf("Welcome to your Task Management Sytem\n");
    printf("What would you like to do today?\n A: Add New Task\n B: View Task \n C: Manage Tasks\n");
    printf("\nEnter your choice:");
    scanf("%c", &main_choice);
    
    switch(main_choice)
    {
        case 'A':
            printf("\n--------------ADD A NEW TASK-------------");
            add_task();
            break;
        case 'B':
            printf("\n----------VIEW YOUR TASKS----------");
            view_task();
            break;
        case 'C':
            printf("\n----------MANAGE YOUR TASKS----------");
            manage_task();
            break;
    }
    
    void add_task(void);
    char name[20];
    char category[20];
    char info[20];
    char date[20];
    char status[20];

    printf("\nTo Add a new task enter the details below\n");
    printf("Name of Task:");
    scanf(" %s", name);
    printf("Category of Task:");
    scanf(" %s", category);
    printf("Information about task:");
    scanf(" %s", info);
    printf("Due Date of Task(dd/mm/yyyy):");
    scanf(" %s", date);
    printf("Status of Task\n TD = To-Do\n IP = In Progress\n CT = Completed Task\nEnter Status:");
    scanf(" %s", status);
    
    
    void view_task(void);
    char task_choice;
    printf("View Tasks by:\nA:Due Date\nB:Category\nC:Status\nD:View All Tasks");
    scanf(" %c", &task_choice);
    if (task_choice == 'A')
    {
        char date_choice;
        printf("A:View Tasks in ascending order\nB: View Tasks in descending order\nEnter your choice:");
        scanf(" %c", &date_choice);
    

    }
    return 0;
}

1 Answers1

0

regarding:

int main()
{
void main_menu(void);
char main_choice;
printf("Welcome to your Task Management Sytem\n");
printf("What would you like to do today?\n A: Add New Task\n B: View Task \n   C: Manage Tasks\n");
printf("\nEnter your choice:");
scanf("%c", &main_choice);

switch(main_choice)
{
    case 'A':
        printf("\n--------------ADD A NEW TASK-------------");
        add_task();
        break;
    case 'B':
        printf("\n----------VIEW YOUR TASKS----------");
        view_task();
        break;
    case 'C':
        printf("\n----------MANAGE YOUR TASKS----------");
        manage_task();
        break;
}

The following is one example of the changes needed in the code:

Separate the function: main_menu().

Note: Each of the other sub functions should receive the same treatment.

#include <ctypes.h>   // includes function: toupper()   

void main_menu(void)
{
    char main_choice = 'z';  // 'Z' is just a place holder

    while( main_choice != 'Q' )
    {
        printf("Welcome to your Task Management System\n");
        printf("What would you like to do today?\n"
               "A: Add New Task\n"
               "B: View Task\n"
               "C: Manage Tasks\n"
               "Q: Quit\n");  

        printf("\nEnter your choice:");
        scanf(" %c", &main_choice);
        
        switch( toupper(main_choice) )
        {
        case 'A':
        printf("\n--------------ADD A NEW TASK-------------");
        add_task();
        break;
    
        case 'B':
        printf("\n----------VIEW YOUR TASKS----------");
        view_task();
        break;
    
        case 'C':
        printf("\n----------MANAGE YOUR TASKS----------");
        manage_task();
        break;

        default:
        printf( "unknown choice, try again\n" );
        break;
        }
    }
    return;
}


int main( void )
{
     main_menu();
}

    
user3629249
  • 15,986
  • 1
  • 19
  • 17