user3562785
user3562785

Reputation: 1

Really simple code with C++ "Identifier not found" issue

I'm doing a project for a C++ class and I can't figure out why it keeps saying "identifier not found" please any assistance would be awesome! I bolded where it says identifiers not found. Intellisense also is telling me "too few arguments in function call" in the exact same spaces. I'm pretty sure it's probably just one thing but I can't figure it out.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int selection=0, lure=0, season=0;
    cout << "Would you like to fish by lure or by season?";
    cin >> selection;
        if (selection==lure){
            **Weather();**
            **WaterClarity();**
        }
        else if (selection == season){
            **Season();**
        }
    system("pause");
    return 0;
}


int Weather(int weather)
{
    cout << "What clarity is the weather today in: " << endl;
    cout << "Clear" << endl << "Cloudy" << endl << "Dark";
}

int WaterClarity(int waterclarity)
{
    cout << "What condition is the water in: "<<endl;
    cout << "Clear" << endl << "Cloudy" << endl << "Murky";
    cin >> waterclarity;
}    

int Season(int season)
{
    int month = 0;
        cout << "Using numbers 1-12 what month is it?";
        cin >> month;
        if (month == 1){
            cout << "The fish in season are: " << endl;
            cout << "Mahi Mahi" << endl << "Jack Crevalle" << endl <<         "Pompano";
            cout << "Redfish" << endl << "Spanish Mackrel";
        }
        else if (month == 2){
        cout << "The fish in season are: " << endl;
        cout << "Cobia"<< endl << "Mahi Mahi" << endl << "Jack Crevalle" << endl << "Pompano";
        cout << "Redfish" << endl << "Spanish Mackrel";
    }
    else if (month == 3){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Cobia" << endl << "Mahi Mahi" << endl << "Jack Crevalle" << endl << "Pompano";
            cout << "Redfish" << endl << "Spanish Mackrel";
        }
        else if (month == 4){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Kingfish" << endl << "Mahi Mahi" << endl << "Jack Crevalle" << endl << "Pompano";
            cout << "Redfish" << endl << "Spanish Mackrel"<<endl<<"Tarpon";
        }
        else if (month == 5){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Kingfish" << endl << "Mahi Mahi" << endl << "Jack Crevalle"<<endl;
            cout << "Tarpon";
        }
        else if (month == 6){
            cout << "The fish in season are: " << endl;
            cout << "Cobia" << endl << "Snapper" << endl << "Mahi Mahi" << endl << "Jack Crevalle" << endl;
            cout << "Tarpon";
        }
        else if (month == 7){
            cout << "The fish in season are: " << endl;
            cout << "Cobia" << endl << "Snapper" << endl << "Mahi Mahi" << endl << "Jack Crevalle" << endl;
            cout << "Tarpon";
        }
        else if (month == 8){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Redfish" << endl << "Mahi Mahi" << endl << "Jack Crevalle" << endl;
            cout << "Tarpon";
        }
        else if (month == 9){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Snapper" << endl << "Mahi Mahi" << endl << "Flounder" << endl;
            cout << "Tarpon"<<endl<<"Kingfish";
        }
        else if (month == 10){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Snapper" << endl << "Mahi Mahi" << endl << "Flounder" << endl;
            cout << "Tarpon" << endl << "Kingfish"<< endl<<"Redfish";
        }
        else if (month == 11){
            cout << "The fish in season are: " << endl;
            cout << "Blackfin Tuna" << endl << "Spanish Mackrel" << endl << "Mahi Mahi" << endl << "Flounder" << endl;
            cout << "Tarpon" << endl << "Kingfish"<<endl<<"Pompano";
        }
        else if (month == 12){
            cout << "The fish in season are: " << endl;
            cout << "Jack Crevalle" << endl << "Mahi Mahi" << endl<<"Spanish Mackrel"<<endl;
            cout << "Tarpon" << endl << "Kingfish"<<"Pompano";
        }
}

Upvotes: 0

Views: 120

Answers (4)

jrd1
jrd1

Reputation: 10716

See here:

int Weather(int weather)
int WaterClarity(int waterclarity);
int Season(int season);

You are doing this:

Weather();
WaterClarity();
Season();

These function calls are different to what you've defined: you've created functions that require a value to be supplied. Hence, your function calls are incorrect as you are calling them with void parameters.

This is why you get the "Identifier not found" error as the compiler is trying to find an function with the name Weather that returns an integer and takes a void parameter. As you don't have any defined (i.e. you only have one that takes an integer parameter), an error is thrown.

To fix this, you need to do two things:

1) Forward declare the functions before using them (before main):

int Weather(int weather)
int WaterClarity(int waterclarity);
int Season(int season);

and, in your case, you need to call the function like this:

Weather(0);
WaterClarity(0);
Season(0);

But, although that's logical, it may seem a bit odd. Hence, a better idea would be to use default arguments (e.g):

int Weather(int weather=0);//to be used as a forward declaration
int Weather(int weather) {
    //check to see if weather is 0, if it is 0 then it has been called like this:
    //`Weather()`
    int returnvalue = 0;
    if (weather == 0) {
        //do something if weather is 0
    }
    else {
        //do something else
    }
    return returnvalue;//you set this value based on your calculation
 }

Also, the current convention for function name is that they are lowercase. Capitalized names are reserved for Classes and Structs. Just an FYI.

Upvotes: 1

songyuanyao
songyuanyao

Reputation: 172864

What you need is forward declaration, put them before main():

int Weather(int weather);
int WaterClarity(int waterclarity);
int Season(int season)
int main()
...

And you should get another error:

error: too few arguments to function 'int Weather(int)'

Then you need to fix the defination of the function, or the code you call the function, to make them consistent.

Upvotes: 0

nittoor
nittoor

Reputation: 113

give a forward declaration for the functions you are using be fore main

int Weather(int weather);
int Season(int season);
int WaterClarity(int waterclarity);

or copy paste the functions above main.

Upvotes: 0

Andr&#233; Puel
Andr&#233; Puel

Reputation: 9179

Put a declaration of the used functions before you use them, so, before main, put:

int Weather(int weather);
int WaterClarity(int waterclarity);
int Season(int season);

Upvotes: 2

Related Questions