-1

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int hours; //hours worked.
double rate; //Hourly rate
double regular; //Regular pay
double overtime; //how many hours the user worked overtime.
double gross; //Gross salary
double federal; //Federal tax of 27%
double medical; //medical insurance, 14%
double net; // Pay after federal tax and medical insurance is taken out.
char c[1];
int Running = 1;
int f = -1;
void option(int opt);


main(void) {

    void workStats(void); //Function that will collect user's number of hours and how much they make an hour.
    void regularPay(void);
    void grossPayWithOvertime(void);
    void totalPayTakingOutTaxes(void);
    void printMenu(void);

    void printMenu(void);
    while (Running == 1) {
        scanf("%d", &f);
        option(f);
        printf("\n");
    }

    return 0;
}
void option(int option) {
    switch (option) {
    case 1:
        workStats();
        break;
    case 2:
        regularPay();
        break;
    case 3:
        grossPayWithOvertime();
        break;
    case 4:
        totalPayTakingOutTaxes();
        break;
    case 5:
        Running = 0;
        break;

    default:
        printf("Sorry, but that was not an option; Please enter one of our choices. Type any number between 1 and 6.");
        system("pause");
    }
        void printMenu(void); {
            printf("==========================================================\n");
            printf("===========Payroll Program==========================\n");
            printf("============================================================\n\n");
            printf("Things you can do here.\n");
            printf("\n1. Tell us about how much you make and how many hours you work \n");
            printf("\n2. Regular Pay, before taxes are included\n");
            printf("\n3. Gross PAy (This includes overtime) \n");
            printf("\n4. Net pay (Taxes taken out of Gross Pay) \n");
            printf("\n5. Exit");

            printf("Please type the number corresponding to the action you wish to take. \n");
        }
        void workStats(void); {
            printf("Now, how many hours do you work a week?");
            scanf("%d", &hours);

            printf("Please tell me how much you make per hour.");
            scanf("%lf", &rate);
        }
        void regularPay(void); {

            regular = rate * hours;

            printf("Regular Pay:%.2lf \n ", regular);
        }
        void grossPayWithOvertime(void); {
            overtime = (hours - 40) * (rate * 1.5);

            printf("Overtime Pay:%.2lf \n ", overtime);

            gross = regular + overtime;

            printf("Gross Pay:%.2lf \n ", gross);
        }
        void totalPayTakingOutTaxes(void); {
            federal = gross * .27;

            printf("Federal Tax:%.2lf  \n", federal);

            medical = gross * .14;

            printf("Medical Insurance :%.2lf \n ", medical);

            net = gross - (federal + medical);

            printf("Net Pay:%.2lf \n ", net);

            system("pause");

    }
}

The issue is when I try to compile it does not recognize my function calls. A cleaning and rebuilding did not solve this issue, (I just programmed this today, so it was not sitting around or anything) and I don't have any outside files that I reference in this code so that is not the issue either. Any help is much appreciated. Full Error: https://puu.sh/wKn4n/00f95f3032.png

Nyako
  • 45
  • 2
  • 9
  • 1
    Are you 100 % sure that your compiler does not give you any warning? Which compiler? – Gerhardh Jul 15 '17 at 18:13
  • Visual Studio 2017, and the warning it jjust gives me those errors, no warnings here. – Nyako Jul 15 '17 at 18:19
  • I hope you do not write any software for the government bodies. If yes I am getting worried ... – 0___________ Jul 15 '17 at 18:20
  • It's usually of great help (also making the question complete) if the __full__ error (if any) is included. – CristiFati Jul 15 '17 at 18:24
  • I will suggest you take any good C book([C Guide](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)) and take your time(no skipping chapters) to understand basic things. These are basic things and you have a very big problem with them. – Seek Addo Jul 15 '17 at 18:42

2 Answers2

4

You have two problems: The first is that you declare the prototypes in the scope of the main function (which you forgot to give a return type by the way). The prototypes should be declared in the global scope.

The second problem is worse, since you're doing something completely invalid, and that is defining the function inside theoption function. They should of course be defined (implemented) in the global scope as well. Defining nested function (functions inside other functions) is not valid C.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 3
    The problem is even more subtle - he's not actually *defining* a function within a function. He's declaring a function followed by semicolon and a block of code. It just happens to compile.... – selbie Jul 15 '17 at 18:17
  • So, write out what the functions do before main()? – Nyako Jul 15 '17 at 18:22
  • Oh and the Semi colon are there because VS whined that there was not one there. – Nyako Jul 15 '17 at 18:23
0

The overall structure of your file should be like this:

#include <this.h>
#include <that.h>

int globalvar; // if you must have globals; you should try to avoid them

static void
workStats(void)
{
    // body of workStats here
}

static void
regularPay(void)
{
    // body of regularPay here
}
// and so on like that, for all functions besides main

int
main(void)
{
    // body of main here
    // you don't need to redeclare the functions
}
zwol
  • 135,547
  • 38
  • 252
  • 361