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;
}
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);
.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With