Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function declaration with string message

I'm getting an "Error: 'message' was not declared in this scope" error for the declaration of the int getValue function when compiling.

This function is supposed to take user inputted integers and deliver them to the main function.

Have I declared the 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's year in 4 digits,\n"
     << "and today's 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's year in 4 digits";
getValue(message)==thisYear;

message="Enter today's 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;
}
like image 203
0x100001 Avatar asked Mar 13 '23 05:03

0x100001


2 Answers

You're missing the type in the function declarations. For example:

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

should be change to something like: int getValue(const std::string& message);.

like image 21
James Adkison Avatar answered Mar 15 '23 23:03

James Adkison


You have to write what kind of data type your parameter is going to use when creating declarations of functions. This applies to all functions you write; whether they be global, or in-scope functions.

Change

int getValue(message);

char getLetter(message);

To

int getValue(const string& message);

char getLetter(char message);

like image 62
user2277872 Avatar answered Mar 16 '23 00:03

user2277872