I'm trying to learn c++ and am getting the following errors when I try and run this simple program that I'm creating.
Error C3867 'budget::check_mort': non-standard syntax; use '&' to create a pointer to member
Error C3867 'budget::check_car': non-standard syntax; use '&' to create a pointer to member
Error C3867 'budget::check_groc': non-standard syntax; use '&' to create a pointer to member
Error C3867 'budget::check_util': non-standard syntax; use '&' to create a pointer to member
I'm not quite sure where to go from here. Searching for the issue seems to point towards needing to make something static or const but I'm not quite sure. Any help would be very much appreciated.
using visual studios community and windows 10 Files below:
.h File
#pragma once
#include <iostream>
#include <string>
#include <ostream>
#include <list>
#include <algorithm>
#include <numeric>
#include <windows.h>
#include <shellapi.h>
using namespace std;
#ifndef BUDGET_H
#define BUDGET_H
class budget {
private:
float mortgage, utilities, groceries, car_payment, misc, income;
public:
budget();
budget(budget& rhs);
~budget();
budget(float mortgage, float utilities, float groceries, float car_payment, float misc, float income);
void input();
void display() const;
bool check_mort() const;
bool check_util() const;
bool check_groc()const;
bool check_car()const;
void additional_resc();
};
#endif // !BUDGET_H
.cpp file
#include "budget.h"
budget::budget() : mortgage{0}, utilities{0}, groceries{0}, car_payment{0}, misc{0}, income{0} { }
budget::budget(budget& rhs): mortgage {rhs.mortgage}, utilities{rhs.utilities}, groceries{rhs.groceries}, car_payment{rhs.car_payment}, misc{rhs.misc}, income{rhs.income}{}
budget::budget(float mort, float util, float groc, float car, float mis, float inco) : mortgage{ mort }, utilities{ util }, groceries{ groc }, car_payment{ car }, misc{ mis }, income{ inco } {
}
budget::~budget(){}
void budget::input() {
cout << "Enter your mortgage payment: ";
cin >> mortgage;
cout << "Enter your utilities payment: ";
cin >> utilities;
cout << "Enter the amount you spend on grocieries for a month: ";
cin >> groceries;
cout << "Enter the total amount that you pay in car payments each month: ";
cin >> car_payment;
cout << "Enter the total sum of any other expenses, such as phone bill, insurance, contribution to savings, etc. : ";
cin >> misc;
cout << "Enter your total income: ";
cin >> income;
}
void budget::display() const{
float x = mortgage + utilities + groceries + car_payment + misc;
cout << "The sum of all of your expenses is " << x << endl;
cout << "Based on your inputs: ";
if (check_mort) {
cout << "Your mortgage is higher than the national average./n Consider taking steps to reduce this such as refinancing or relocating./n ";
}
if (check_car) {
cout << "Your car payments are higher than the average. Consider finding alternate transportation and downgrading/n";
}
if (check_groc) {
cout << "Your grocieries are higher than the average. Consider finding cheaper alternatives and not eating out./n";
}
if (check_util) {
cout << "Your utilities cost is higher than the average. Consider finding ways to reduce usage, such as raising or lowering the thermometer./n";
}
}
void budget::additional_resc() {
ShellExecute(0, 0, L"https://www.thebalance.com/start-getting-out-of-debt-960852", 0, 0, SW_SHOW);
}
bool budget::check_mort() const {
if (mortgage > 1400){
return true;
}
else {
return false;
}
}
bool budget::check_util() const {
if (utilities > 114) {
return true;
}
else {
return false;
}
}
bool budget::check_groc() const {
if (groceries > 412) {
return true;
}
else {
return false;
}
}
bool budget::check_car() const {
if (car_payment > 640) {
return true;
}
else {
return false;
}
}
Main file
#include "budget.h"
int main()
{
int I = 0;
char choice = 'n';
budget Budget;
while (I == 0) {
cout << "Hello, thank you for using your budget butler. /n";
cout << "Please enter the following to calculate your budget: ?/n";
Budget.input();
Budget.display();
cout << "Would you like to learn more about ways to reduce your debt? y or n";
cin >> choice;
if (choice == 'y') {
Budget.additional_resc();
}
cout << "What would you like to do now? /n/n/n";
cout << "0. Quit Program?\n";
cout << "1. Enter new budget information\n";
cin >> I;
if (I == 0) {
I++;
}
else if (I == 1) {
budget Budget1;
Budget1.input();
Budget1.display();
}
}
return 0;
}
In budget::display()
, your if
statements are not calling the class methods to evaluate their return values. They are instead evaluating the memory addresses of the methods, and doing so in a non-standard way, hence the errors.
You are missing parenthesis to call the methods, eg:
if (check_mort()) {
...
}
if (check_car()) {
...
}
if (check_groc()) {
...
}
if (check_util()) {
...
}