Just a viewer
Just a viewer

Reputation: 11

Why doesn't my program touch the functions I made?

I am having issues with running the following code, it runs but doesn't display anything

  #include <iostream>
using namespace std;

class Calorie {
public:
    string name;
    double height;
    double weight;
    char gender;
    string fname;
    string fgroup;
    int cal;
    double recommendcal;
    double temp;
    double RecCal();
    Calorie(string foodname, string foodgroup, int calories);
    Calorie(string n, double h, double w, char g);

};
class Foodgroup : public Calorie {
    int rec;
    void Grains();
    void Proteins();
    void Vege();
    void fruit();
    void Dairy();

};


int main() {
    string foodname;
    string foodgroup;
    int calories;
    string name;
    double height;
    double weight;
    char gender;


    cout << "Please enter your name:";
    cin >> name;
    cout << "Please enter your height in inches:";
    cin >> height;
    cout << "Please enter your weight in pounds:";
    cin >> weight;
    cout << "Please enter your gender F/M:";
    cin >> gender;

    Calorie human(name, height, weight, gender);
    Calorie RecCal();

    cout << "Enter Food name:";
    cin >> foodname;
    cout << "Enter Food type:";
    cin >> foodgroup;
    cout << "Enter number of calories:";
    cin >> calories;

    Calorie food(foodname, foodgroup, calories);
    if (foodgroup == "grains") {

        Foodgroup Grains();

    }
    else if (foodgroup == "proteins" || foodgroup == "Proteins") {

        Foodgroup Proteins();
    }
    else if (foodgroup == "fruits" || foodgroup == "Fruits") {

        Foodgroup fruits();
    }
    else if (foodgroup == "vegetables" || foodgroup == "Vegetables") {

        Foodgroup Vege();
    }
    else if (foodgroup == "dairy" || foodgroup == "Dairy") {

        Foodgroup Dairy();
    }

    return 0;
}


Calorie::Calorie(string n, double h, double w, char g) {
    name = n;
    height = h;
    weight = w;
    gender = g;


}
Calorie::Calorie(string foodname, string foodgroup, int calories) {
    fname = foodname;
    fgroup = foodgroup;
    cal = calories;
}

double Calorie::RecCal() {
    if (gender =='M' || gender == 'm') {

        recommendcal = 2500;
        if (height <= 70) {
            temp = 70 - height;
            temp = 25 * temp;
            recommendcal = recommendcal - temp;

        }else if (height >= 70) {
            temp = height - 70;
            temp = 25 * temp;
            recommendcal = recommendcal + temp;

        }
        if (weight <= 165) {
            temp = 165 - weight;
            temp = 10 * temp;
            recommendcal = recommendcal - temp;

        }
        else if (weight >= 165) {
            temp = weight - 165;
            temp = 10 * temp;
            recommendcal = recommendcal + temp;

        }

    }
    else if (gender == 'F' || gender == 'f') {

        recommendcal = 2300;
        if (height <= 70) {
            temp = 70 - height;
            temp = 25 * temp;
            recommendcal = recommendcal - temp;

        }
        else if (height >= 70) {
            temp = height - 70;
            temp = 25 * temp;
            recommendcal = recommendcal + temp;

        }
        if (weight <= 165) {
            temp = 165 - weight;
            temp = 5 * temp;
            recommendcal = recommendcal - temp;

        }
        else if (weight >= 165) {
            temp = weight - 165;
            temp = 5 * temp;
            recommendcal = recommendcal + temp;

        }
    }
    cout << "You're recommended calorie intake per day is: " << recommendcal << " calories." << endl;
    return recommendcal;


}


void Foodgroup::Grains() {

    rec = recommendcal * .4;
    if (cal <= rec) {

        cout << "You have not hit the calorie limit for this food group";
    }
    else {

        cout << "You have hit the calorie limit for this food group ";
    }

}

void Foodgroup::Proteins() {

    rec = recommendcal * .4;
    if (cal <= rec) {

        cout << "You have not hit the calorie limit for this food group";
    }
    else {

        cout << "You have hit the calorie limit for this food group ";
    }

}
void Foodgroup::Vege() {

    rec = recommendcal * .4;
    if (cal <= rec) {

        cout << "You have not hit the calorie limit for this food group";
    }
    else {

        cout << "You have hit the calorie limit for this food group ";
    }

}void Foodgroup::fruit() {

    rec = recommendcal * .4;
    if (cal <= rec) {

        cout << "You have not hit the calorie limit for this food group";
    }
    else {

        cout << "You have hit the calorie limit for this food group ";
    }

}void Foodgroup::Dairy() {

    rec = recommendcal * .4;
    if (cal <= rec) {

        cout << "You have not hit the calorie limit for this food group";
    }
    else {

        cout << "You have hit the calorie limit for this food group ";
    }

}

I am unsure why the this occur, if you could help me resolve the issue it would be greatly appreciated. I have no idea on how to resolve this issue, it all looks like it should work but something isn't clicking. The codes purpose is to calculate the amount of calories on takes and see if they have met their recommended calorie intake. It is also supposed to ask three times, three different foods/drinks since we don't just eat/drink one thing a day.

Upvotes: 0

Views: 50

Answers (2)

Ron
Ron

Reputation: 15501

Replace:

void Human(Calorie name, Calorie height, Calorie weight, Calorie gender)

with:

void Human(std::string name, double height, double weight, char gender)

You have the wrong types in a function signature.

Upvotes: 1

Demonxus
Demonxus

Reputation: 64

Ron, that's right, it solves this problem but there is another problem :

void foodgroup::Grains() {

    rec = recommendcal * .4;
    if (cal <= rec) {

        cout << "You have not hit the calorie limit for this food group";
    }
    else {

        cout << "You have hit the calorie limit for this food group ";
    }

}

[Error] 'recommendcal' was not declared in this scope

There is no declaration of 'recommendcal'

Upvotes: 0

Related Questions