Function declaration with string message

I get the error "Error:" "not declared in this area" for declaring int getValue function at compile time.

This function should take integers entered by the user and deliver them to the main function.

Did I declare functions correctly?

#include <iostream>
#include <string>

using namespace std;


int getValue(message); 
// Compiler message: [Error] 'message' was not declared in this scope.

char getLetter(message);



int main()
{

int thisYear, thisMonth, year, month, ageYear, ageMonth;
char again = 'y';
string message;
// display program instructions
cout << "This program asks you to enter today year in 4 digits,\n"
     << "and today month number.\n\n"
     << "Then you will be asked to enter your birth in 4 digits,\n"
     << "and your birth month in 2 digits.\n\n"
     << "The program will calculate and display your age in years and months.\n";



message="Enter today year in 4 digits";
getValue(message)==thisYear;

message="Enter today month in 2 digits";
getValue(message)==thisMonth;


do
{

    message="Enter your birth year in 4 digits";
    getValue(message)==year;

    message="Enter your birth month in 2 digits";
    getValue(message)==month;


    ageYear = thisYear - year;
    ageMonth = thisMonth - month;


    if (thisMonth < month)
    {
        ageYear--;
        ageMonth += 12;
    }


    cout << "\nYou are " << ageYear << " years and " << ageMonth << " months old.\n";

    message="Do you want to calculate another age? (y/n)";

    getLetter(message)==again;

    again = tolower(again);

}while (again == 'y');

return 0;
}

/* the function getValue returns an integer value
   entered by the user in response to the prompt 
   in the string message */
int getValue(message)
{
// declare variables
// declare an integer value to enter a value
int value;

cout << message;

cin >> value;

return value;
}

/* the function getLetter returns a character value
   entered by the user in response to the prompt
in the string message */
char getLetter(message)
{

char letter;

cout << " Do you wish to enter another date? (y/n)";

cin >> letter;

return letter;
}
+4
source share
2 answers

You must write what data type will be used by your parameter when creating function declarations. This applies to all the functions you write; be it global or domestic functions.

Change

int getValue(message);

char getLetter(message);

To

int getValue(const string& message);

char getLetter(char message);

+4
source

You are missing the type in function declarations. For instance:

int getValue(        message);
//           ^^^^^^^ type?

- : int getValue(const std::string& message);.

+3

Source: https://habr.com/ru/post/1629986/


All Articles