1

I'm extremely new to the coding scene and, even more so to coding with C++. I'm currently building a side program for my class as it was strongly recommended, but I can't seem to get it to compile. I keep getting a C4430 error (missing type specifier - int assumed). I'm not seeing anything like this in my reading material either, so I figured I'd reach out here for help as a second set of eyes is always a good idea. If it matters, I am coding this with Microsoft Visual Studio 2019 Community Edition. I'm still learning, but I'm also used to coding in Java at this point so I'm at a loss.

The program itself is a program I have written in Java, that I have adapted for use in C++. It's a very basic salary calculation program that spits out weekly, monthly, and annual wages while also accounting for Taxes. Initially, it had included the scanner utility in Java, but I haven't seen anything like that in C++ yet. Ideally, it would spit this information out without a problem.
I have tried adding return 0; to the end of my code, but I am still getting the C4430. I have also reclassed my main as double instead of int, to no avail.

I have included my code, below:

#include <iostream>
double salaryCalculator; main ()
{
double hourlyWage = 15.00;
int hoursWorkedWeek = 40;
double weeklyWage = 0.0;
double monthlyWage = 0.0;
double annualWage = 0.0;
double overtimeHours = 3.0;
double overtimeMulti = 1.5;
double overtimeHourlyWage = 0.0;
double overtimeTotalWage = 0.0;

overtimeHourlyWage = hourlyWage * overtimeMulti;
overtimeTotalWage = overtimeHourlyWage * overtimeHours;
std::cout << "You have /n" << overtimeHours << "hours of overtime at a rate of " << overtimeHourlyWage << "an hour, for a total of " << overtimeTotalWage;

weeklyWage = overtimeTotalWage + (hoursWorkedWeek * hourlyWage);
std::cout << "Your weekly wage is: /n" << weeklyWage;

monthlyWage = weeklyWage * 4;
std::cout << "Your monthly wage is: /n" << monthlyWage;

annualWage = weeklyWage * 52;
std::cout << "Your annual wage before taxes is: /n" << annualWage;

enum class TaxDeductions;
{
};
        double incomeTax = 0.11;
        double stateTax = 0.04;
        double socialSecurityTax = 0.062;
        double medicareTax = 0.0145;

        double firstWTax = weeklyWage * incomeTax;
        double secondWTax = weeklyWage * stateTax;
        double thirdWTax = weeklyWage * socialSecurityTax;
        double fourthWTax = weeklyWage * medicareTax;
        double weeklyTax = firstWTax + secondWTax + thirdWTax + fourthWTax;

        double firstMTax = monthlyWage * incomeTax;
        double secondMTax = monthlyWage * stateTax;
        double thirdMTax = monthlyWage * socialSecurityTax;
        double fourthMTax = monthlyWage * medicareTax;
        double monthlyTax = firstMTax + secondMTax + thirdMTax + fourthMTax;

        double firstATax = annualWage * incomeTax;
        double secondATax = annualWage * stateTax;
        double thirdATax = annualWage * socialSecurityTax;
        double fourthATax = annualWage * medicareTax;
        double annualTax = firstATax + secondATax + thirdATax + fourthATax;



        double weeklyTakeHome = weeklyWage - weeklyTax;
        double monthlyTakehome = monthlyWage - monthlyTax;
        double annualTakeHome = annualWage - annualTax;

        std::cout << "Your weekly total take home is /n" << weeklyTakeHome;
        std::cout << "Your monthly total take home is: /n" << monthlyTakehome;
        std::cout << "Your annual total take home is /n" << annualTakeHome;

        return 0;
    }

Thank you for your time.

Steve P.
  • 25
  • 6
  • 1
    Does this answer your question? [What should main() return in C and C++?](https://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c) – Richard Critten Jan 12 '20 at 19:17
  • 1
    If you are new to C++, why do you write so much code at a time before testing if it works as you intend? – Jesper Juhl Jan 12 '20 at 19:19
  • The link helps me explain why I am getting and answers my question, as well as a treasure trove of information I'll probably need. Thank you for the help! The reason for so much code before testing is that I got a little overzealous with adapting my program to a new coding language and did not think to test as I progressed, a habit I intend to break. Thank you for the feedback. – Steve P. Jan 14 '20 at 01:21

2 Answers2

3

If you remove the function's body for a moment, you'll see this:

double salaryCalculator; main ()
{
}

Or, with better formatting:

double salaryCalculator;  // variable declaration

main () // function definition
{
}

But you haven't specified the return type of main, so it defaulted to int, and the compiler is warning you about that.

To please the compiler, specify the return type explicitly:

int main(void) {
    // code here
}
ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • 1
    Adding `void` there is a needless backwards step likely only to confuse the OP. – Lightness Races in Orbit Jan 12 '20 at 20:09
  • Understood, though I do have a follow-up question: does void work the same way in C++ as it does in Java (in that it does not return anything)? I appreciate your help and feedback. – Steve P. Jan 14 '20 at 01:24
  • @SteveP., as you can see, the `void` is not the return type here (`int` is). If it were `void main(void)`, that would mean that `main` doesn't return anything (which isn't true since it should return an integer). The `void` in the parentheses (instead of the parameter list) means that the function doesn't accept any arguments. – ForceBru Jan 14 '20 at 05:56
  • Alright, I think I understand now. I appreciate your further clarification and helping me to understand the code. – Steve P. Jan 16 '20 at 01:02
3

You forgot to specify the return type for the entry point main ()!

Add int before main

#include <iostream>


double salaryCalculator;


int main() {
    //code body..
    return 0;
}
Oh-Ben-Ben
  • 163
  • 2
  • 7
  • I got it, I think. So the primary point here, if I'm understanding correctly, is that I need to define the return type in C++ as I would in Java. I'm not sure how I didn't think of this sooner, thank you for the feedback and help in understanding. – Steve P. Jan 14 '20 at 01:22
  • @SteveP. you're welcome – Oh-Ben-Ben Jan 14 '20 at 06:44