### Calling a function for the first time (date)

I am writing a program that calls a function for the first time. The assignment is to write a program that prompts the user to enter a day, month, and year (as integers). The program then calls a function that returns a string representing the date in the format “Month Day, Year." I know how to prompt the user to enter the integers and I know how to print out the results but I am confused on calling a function. Is there a pre-known function out there that I am supposed to use or do I make this up completely? The code attached is how I started but I know I am not going in the correct direction.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` `````` #include #include using namespace std; int date_return(string mm) { int d; int m; int y; cout << "Please enter a day of the month, in integer form: "; cin >> d; cout << "Please enter a month, in integer form: "; cin >> m; cout << "Please enter a year, in integer form: "; cin >> y; if(m=1){ mm = January; } else if(m=2){ mm = February; } else if(m=3){ mm = March; } else if(m=4){ mm = April; } else if(m=5){ mm = May; } else if(m=6){ mm = June; } else if(m=7){ mm = July; } else if(m=8){ mm = August; } else if(m=9){ mm = September; } else if(m=10){ mm = October; } else if(m=11){ mm = November; } else(m=12);{ mm = December; } cout << "The date you entered is: " << mm << d << "," << y << endl; return 0; }``````
 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````#include #include // function that returns a string representing the date in the format “Month Day, Year." // return type: std::string // input: three integers representing the year, month (january=1), and day // invariant: input contains valid values eg. month in [1,12] std::string date_string( int year, int month, int day ) { // the tail part of the date string containing text representations of day and year const std::string tail = std::to_string(day) + ", " + std::to_string(year) ; // return a string with the name of the month added as the prefix switch(month) // use a lookup table (an array) instead? { case 1 : return "January " + tail ; case 2 : return "February " + tail ; case 3 : return "March " + tail ; case 4 : return "April " + tail ; case 5 : return "May " + tail ; case 6 : return "June " + tail ; case 7 : return "July " + tail ; case 8 : return "August " + tail ; case 9 : return "September " + tail ; case 10 : return "October " + tail ; case 11 : return "November " + tail ; case 12 : return "December " + tail ; default : return "invalid month " + tail ; } } int main() { std::cout << "enter date as three space separated integers yyyy mm dd: " ; int yyyy, mm, dd ; std::cin >> yyyy >> mm >> dd ; // pass the three integers yyyy, mm and dd as input the function // and print out the string that the function returns std::cout << date_string( yyyy, mm, dd ) << '\n' ; }``````
@shimshim96:

You need to double-check all your if statements, and make sure you understand the difference between the assignment operator `=` and the equality comparison operator `==`.
Topic archived. No new replies allowed.