Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3042

Need Help on Zoo program

$
0
0
Hi, I just got this assignment and am struggling a little bit. I am getting multiple errors. The errors are:

Line
Error 1 error C2660: 'calcAmph' : function does not take 2 arguments 27
Error 2 error C2660: 'calcMam' : function does not take 2 arguments 31
Error 3 error C2660: 'calRep' : function does not take 2 arguments 35
Error 4 error C2082: redefinition of formal parameter 'height' 73
Error 5 error C2082: redefinition of formal parameter 'age' 73
Error 6 error C2082: redefinition of formal parameter 'height' 97
Error 7 error C2082: redefinition of formal parameter 'age' 97
Error 8 error C2082: redefinition of formal parameter 'height' 121
IntelliSense: too few arguments in function call 27
IntelliSense: too few arguments in function call 31



The purpose of this program is to determine the amount of food eaten by a certain kind of animal. Rather than using one big pile of main( ), you need to use functions for these calculation that incorporate pass-by-value parameters. In addition, you need to include various int or double const declarations within your program. Finally, embed your program in a loop so that the calculation can be repeated as often as the user wishes.

IN ORDER TO RECEIVE FULL CREDIT, YOU MUST DEFINE AND CALL FUNCTIONS AND PASS ARGUMENTS.

You should base your calculations on the following table:

Mammals
1 lb for each 10 lbs in weight
1/3 lb for each foot in height
1/10 lb for each 5 years of age
Add an extra 15% of food if the animal can run faster than a human

Amphibians
2/3 lb for each 5 lbs in weight
1/4 lb for each 6 inches in length
1/5 lb for each 4 years in age
Add an extra 10% of food if the animal is pregnant

Reptiles
1/5 lb for each 6 lbs in weight
1/2 lb for each foot in length
Deduct 10% of food during winter


What I have so far is:

Code:



#include <iostream>
#include <string>
#include <cmath>
using namespace std;


double calcMam(double weight, double height, double age);
double calcAmph(double weight, double height, double age);
double calRep(double weight, double height, double age);

int main()
{
bool userWantsToContinue = true;

while(userWantsToContinue)
{
    // Determine what the user wants
    string userRequest;
    cout << "Whaddya want? [0]Mammal or [1]Amphibian or [2]Reptile:: ";
    cin >> userRequest;

    double weight = 0 , height = 0, totfood = 0;

 
    if(userRequest == "0" || userRequest == "0")
    {
        totfood = calcAmph(weight, height);
    }
    if(userRequest == "1" || userRequest == "1")
    {
        totfood = calcMam(weight, height);
    }
    if(userRequest == "2" || userRequest == "2")
    {
        totfood = calRep(weight, height);
    }
 

    cout << "You need "<< totfood << "pounds of food" << endl;

    // Determine if the user wants to go again
bool gotUserInput = false;  // signals if the user entered a valid yes or no
    while (!gotUserInput)
    {
        cout << "Try again? [Y/N]: ";
        string tryAgainStr;
        cin >> tryAgainStr;
       
        if(tryAgainStr == "Y" || tryAgainStr == "y")
        {
            gotUserInput = true; // the user entered someting valid
            userWantsToContinue = true; // continue the loop again
        }
        else if(tryAgainStr == "N" || tryAgainStr == "n")
        {
                        gotUserInput = false; // the user entered someting valid
            userWantsToContinue = false; // continue the loop again
        }
        else
        {
            // the user entered bad input, we'll ask the user again for y/n
            cout << "Error: Invalid input: " << tryAgainStr << endl;
        }

    } // end while(!gotUserInput)

} // end while(userWantsToContinue)
return 0;
} // end main

double calcMam(double weight, double height, double age)       
{
        const double food = 1, height = .66, age = .10;
        double totFood = 0, height_food = 0;
        char ans1, ans2;       


        cout << "Gimme its weight in lbs ";
        cin >> weight;
        cout << "Gimme its height in feet: ";
        cin >> height;
        cout << "Can it run faster than a human?  [Y/N]:";
        cin >> ans1,ans2;
       
        if (ans1 == 'Y' || ans1 == 'y')

                totFood = totFood + (totFood * .15);

               
        totFood = weight*food;
        height_food = height*height;
        return (totFood + height_food);
}

double calcAmph(double weight, double height, double age)       
{
        const double food = .66, height = .25, age = .20;
        double totFood = 0, height_food = 0;
        char ans1, ans2;       


        cout << "Gimme its weight in lbs ";
        cin >> weight;
        cout << "Gimme its height in feet: ";
        cin >> height;
        cout << "Is it pregnant?  [Y/N]:";
        cin >> ans1,ans2;
       
        if (ans1 == 'Y' || ans1 == 'y')

                totFood = totFood + (totFood * .10);

               
        totFood = weight*food;
        height_food = height*height;
        return (totFood + height_food);
}

double calRep(double weight, double height)       
{
        const double food = 1, height = .66, age = .10;
        double totFood = 0, height_food = 0;
        char ans1, ans2;       


        cout << "Gimme its weight in lbs ";
        cin >> weight;
        cout << "Gimme its height in feet: ";
        cin >> height;
        cout << " it run faster than a human?  [Y/N]:";
        cin >> ans1,ans2;
       
        if (ans1 == 'Y' || ans1 == 'y')

                totFood = totFood + (totFood * .15);

        cout << "Is it winter?  [Y/N]:";
        cin >> ans1,ans2;
       
        if (ans1 == 'Y' || ans1 == 'y')

                totFood = totFood - (totFood * .10);

               
        totFood = weight*food;
        height_food = height*height;
        return (totFood + height_food);
}


Viewing all articles
Browse latest Browse all 3042

Trending Articles