0

I am very new to programming, especially in C++, and am trying to build my first project on my own. A budget program. Criticism is welcome. I'm using a constructor in my main file to call my functions from a separate class file. However, I'm getting an error that says the object that I'm using is "of non-class type 'PromptUser().'" Here is my code.

Main.cpp

#include <iostream>
#include "PromptUser.h"

using namespace std;

int main()
{
    PromptUser pu();
    pu.prompt();
    pu.addPay();
    return 0;
}

PromptUser.h

#ifndef PROMPTUSER_H
#define PROMPTUSER_H


class PromptUser
{
    public:
        PromptUser();
        void prompt();
        void addPay();
        float netPay = 0.00; //net pay
        float netPay2 = 0.00; //2nd net pay
        float totalPay = 0; // sum of all paychecks
        int decision = 0; // variable to hold int decisions

};

#endif // PROMPTUSER_H

PromptUser.cpp

#include "PromptUser.h"
#include <iostream>

using namespace std;


PromptUser::PromptUser()
{

}

void PromptUser::prompt(){
//prompting the user for input
cout << "This is a budget program. \n\n";
cout << "Please enter your net pay for the week: $";
cin >> netPay; //user enters first net pay
cout << "Your net pay is $" << netPay << endl; //program displays net pay 1 to user
cout << "Would you like to add another paycheck? | 1 = YES 2 = NO : "; //prompts user       to add another check
cin >> decision; //user chooses yes or no

}

void PromptUser::addPay(){
    //This needs to be in it's own function so it can be recursive
    switch (decision) {

    case 1://user enters a second net pay
        cout << "Please enter the net pay for the second check: $";
        cin >> netPay2; // user enters 2nd net pay
        totalPay = netPay + netPay2; // total for pay is calculated
        cout << "This is your total pay for this week: $" << totalPay;
        break;

    case 2:// user continues
        break;

    default:
        cout << "Please enter a valid response | 1 = YES 2 = NO : ";
        addPay();
    }
}

The error is being thrown in the main file. It will not progress past line 9 were it reads pu.prompt();

Not sure where I'm going wrong here.

Ryan Buck
  • 47
  • 9
  • 1
    The [most vexing parse](http://en.wikipedia.org/wiki/Most_vexing_parse) claims another victim. `PromptUser pu();` => `PromptUser pu;` – user657267 Apr 20 '15 at 05:18
  • @Smac89 Such a thing cannot be the cause of a compiler error. C++ source files are by definition separately translated and in a separate logical phase linked into an executable or collected into a library. – Lars Viklund Apr 20 '15 at 13:20

0 Answers0