Quantcast
Viewing all articles
Browse latest Browse all 20

Date manipulation question

Here is my new code it worked at first ran it a third time and it crashed and still crashes.

Any suggestions??

# include <iostream>
# include <cstdlib>
# include <string>
using namespace std;
//function prototype
void DatePrint(const char *Date);
int main()
{
	char Date[20];
	cout<<"Enter a date in the following format mm/dd/yyyy: ";
	cin>>Date;
	DatePrint(Date);
	cout<<endl;
	return 0;
}
void DatePrint(const char *Date)
{
	int month;
	int day;
	int year;
	char mm[3];
	char dd[3];
	char *MonthStr[]={"January", "Febuary", "March","April", "May", "June", "July","September", "October", "November","December"};
	// input array to separate function arrays
	mm[0] = Date[0];
	mm[1] = Date[1];
	mm[2] = '\0';
	dd[0] = Date[3];
	dd[1] = Date[4];
	dd[2] = '\0';
	//int equivalent/conversion
	month = atoi(mm);
	day = atoi(dd);
	year = atoi(Date + 6);
	if (month > 12 || month < 1 || !day || !year) //validation of input
	{
		cout<<"Big dummy follow instructions\n";
	}
	else
		cout<<MonthStr[month - 1]<<" "<<day<<", "<<year<<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>