2 Replies - 240 Views - Last Post: 12 October 2012 - 09:04 AM Rate Topic: -----

#1 AuburnChicky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-October 12

How do I get this code to properly translate the numerical date?

Posted 12 October 2012 - 08:41 AM

I have worked more on this program lately and believe
I am almost done but there is one last part i am struggling with;
the year. The code i currently have works if you type a year between
2012-2019. The assignment requires us to field dates between 2012-2090.
Basically I need help finding an efficient way to code for how to
concatenate the last part of the year with the string "Two Thousand and". Any help is appreciated! Thanks! <3Andrea



#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;

int main()
{
	int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	string month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 
	string todays[] = {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth", "Eleventh", "Twelveth", "Thirteenth", "Fourteenth", "Fifteenth", "Sixteenth", "Seventeenth", "Eighteenth", "Nineteenth", "Twentieth", "Twenty First", "Twenty Second", "Twenty Third", "Twenty Fourth", "Twenty Fifth", "Twenty Sixth", "Twenty Seventh", "Twenty Eighth", "Twenty Ninth", "Thirtieth", "Thiry First"};
	string todays2[] = {"Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
	string single[] = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" "Ten", "Eleven" "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};

	int m;
	int y;
	int d;
	
	cout << "Please enter a date: " << endl;
	cout << "Month: " << endl; 
	cin >> m; 
	cout << "Day: " << endl;
	cin >> d;
	cout << "Year: " << endl;
	cin >> y;
	if( (y%4) == 0 && (y!= 100) || (y%400) == 0)
		days[1] = 29;
	else
		days[1] = 28;
//	cout << days[1] << endl;
//	system ("pause");
	if(y < 2000 || y > 2090)
	{
		cout << "Invalid year!";
		cout << "Please enter a valid year: " << endl;
		cin >> y;
	}
	if(m < 1 || m > 12)
	{
		cout << "Invalid month entry!" << endl;
		cout << "Enter valid month: " << endl;
		cin >> m;
	}
	//if(d <= days[d])

	int x =0;
	string a;
	x = y - 2000;
	if(x < 20)
		a = single[x-3];


		

	cout << month[m-1] << ", " << todays[d-1] << ", " << "Two Thousand and "+ a << endl;


	system("pause");
}



Is This A Good Question/Topic? 0
  • +

Replies To: How do I get this code to properly translate the numerical date?

#2 rfs02  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 26
  • View blog
  • Posts: 70
  • Joined: 30-September 12

Re: How do I get this code to properly translate the numerical date?

Posted 12 October 2012 - 08:47 AM

In English, everything from 20 to 99 is fairly simple to convert to words. You just need to find the "tens" unit, "Twenty", "Thirty", etc... then convert the last digit "One", "Two", ...
Was This Post Helpful? 0
  • +
  • -

#3 AuburnChicky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-October 12

Re: How do I get this code to properly translate the numerical date?

Posted 12 October 2012 - 09:04 AM

View Postrfs02, on 12 October 2012 - 08:47 AM, said:

In English, everything from 20 to 99 is fairly simple to convert to words. You just need to find the "tens" unit, "Twenty", "Thirty", etc... then convert the last digit "One", "Two", ...


Oh I know. That's my problem, i don't know how to do that. I've been trying.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1