Quantcast
Viewing all articles
Browse latest Browse all 20

Date manipulation question

Wayne

This is what I attempted to do. It will compile but any date prints the else statement.

# include <string>
#include <iostream>
using namespace std;
void GetMonth(string & );
void GetDay(string &);
void GetYear(string &);
int main()
{
string date;
string Month;
string Day;
string Year;
  cout << ("Please enter a date (format: mm/dd/yyyy): ");
  cin >> date;
  GetMonth(date);
  GetDay(date);
  GetYear(date);
    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;
	}
    return 0;
}
void GetMonth(string &date)
{ 
	string Month;
  Month =  date.substr(0,2);
}
void GetDay(string &date)
{
	string Day;
    Day = date.substr(3,2);
}
void GetYear(string &date )
{
	string Year;
    Year = date.substr(6,4);
}


Viewing all articles
Browse latest Browse all 20

Trending Articles



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