Hey fox... got a problem in codding im a newbie at this so take it easy on me ...

The question
Write a C++ program by completing the following steps:
Write a value-returning string function called MonthAbbrev that takes an int value as a parameter. The parameter, month, represents the number of the month. The function returns a string containing the three-letter abbreviation for the corresponding month number. Assume that the month number is in the range of 1 to 12.
Modify the function in Step 1 to handle month numbers that are not in the valid range by returning the string “Inv”.
Write the main function that reads an integer number from keyboard, call the function using the read in number as argument, and display the three-letter abbreviation returned by the function.
what i have done so far

#include<iostream>
using namespace std;
int k;
string MonthAbbrev
{
string mon[] = {"JAN" ,"FEB", "MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
if(k>0 && k<13)
return mon[k-1];
return "Inv";
}
int main()
{
int a;
cout <<" enter month number  u want ";
cin >>a ;
cout << MonthAbbrev(a)<< endl;
return 0;
}

c'mon guys im sure someone can help

hey bro' , I made your program in one function . Separate it in needed functions)

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <string>

     
using namespace std;

int main(int monNumber)
{
string mon[] = {"JAN" ,"FEB", "MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
cout<<"enter a number between 1-12 :";
cin>>monNumber;
if(monNumber>0 && monNumber<13) {
	 cout<<mon[monNumber-1]; //because the array starts at 0
}



getch();
return 0;
}

Dude thanks alot...Check Your PM

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

string MonthAbbrev(int k) //fixd
{
string mon[] = {"JAN" ,"FEB", "MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
if(k>0 && k<13)
return mon[k-1];

}
int main()
{
int a;
cout <<" enter month number  u want ";
cin >>a ;
cout << MonthAbbrev(a)<< endl;

return 0;
}
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

string MonthAbbrev(int k) //fixd
{
string mon[] = {"JAN" ,"FEB", "MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
if(k>0 && k<13)
return mon[k-1];

}
int main()
{
int a;
cout <<" enter month number  u want ";
cin >>a ;
cout << MonthAbbrev(a)<< endl;

return 0;
}

Thanks dude Check ur PM

Why all these unnecessary includes???? at least string and iostream will do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.