Quantcast
Channel: Date manipulation question
Viewing all articles
Browse latest Browse all 20

Date manipulation question

$
0
0
Here is the code I have and it works. I would like to put the "If" statements in their own function and call it in the main. Have been unsuccessful thus far.
# include <string>
#include <iostream>
using namespace std;
int main()
{
string date;
string Month;
string Day;
string Year;
  cout << ("Please enter a date (format: mm/dd/yyyy): ");
  cin >> date;
  Month = date.substr(0,2);
  Day = date.substr(3,2);
  Year = date.substr(6,4);
    if (Month == "01")
    {
      cout << "January " << Day << ","<< Year<<endl;          
    }
    else if(Month == "02")
    {
      cout << "February "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "03")
    {
      cout << "March "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "04")
    {
      cout << "April "<< Day << " "<< Year<<endl;           
    }
    else if(Month == "05")
    {
      cout << "May "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "06")
    {
      cout << "June "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "07")
    {
      cout << "July "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "08")
    {
      cout << "August "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "09")
    {
      cout << "September "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "10")
    {
      cout << "October "<< Day << ", "<< Year<<endl;           
    }
    else if(Month == "11")
    {
      cout << "November "<< Day << ", "<<Year<<endl;           
    }
    else if(Month == "12")
    {
      cout << "December "<< Day << ", "<< Year<<endl;           
    }
    else
    {
		cout << "Idiot you enter the date incorrectly "<<endl;
	}
}


Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>