Hello! I am still learning the basics of C++ and was trying to write this functions that returns the name of the month corresponding with the number the user inputs (1-12). However I keep getting these two errors.
C:\CPP_Programs\Minigame\ReturnNameOfMonth\main.cpp: In function 'int main()':
C:\CPP_Programs\Minigame\ReturnNameOfMonth\main.cpp:13: error: a function-definition is not allowed here before '{' token
C:\CPP_Programs\Minigame\ReturnNameOfMonth\main.cpp:50: error: expected '}' at end of input
I understand that this code isn't fully finished (as I don't ask the user to cin anything). However, with this problem fixed, it shouldn't be too hard to implement.
Your problem is that you are defining the function within main. You should rather have it outside, and cal it from main. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
constchar* int2month(int month) {
// get the month...
return pszReturnValue;
}
int main() {
int month;
std::cout << "Enter a number from 1-12: ";
std::cin >> month;
std::cout << "The corresponding month is " << int2month(month) << "\n";
return 0;
}