I'm still working on it though!
Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo
mabufo wrote:I need help finding the day....
like it says the 23rd of january....
How do I find the underlined number based on what the user gives me? The answer is probably right under my nose too =/
Johnny T wrote:Well !! My gast is flabbered....
Some superb responses to the first task and some absolutely brilliant solutions...
I haven't had chance to compile them all yet but I will and its great to see that people are learning from this....
We could maybe make this a regular feature.. chuck in a "beginners task" now and again ??
Good on ya lads and lasses, keep up the very good work !
/*Get Date program...
This program takes the user input and makes it into the
corresponding date of the year! Example: If the user inputs
1, the output is: 1st January 2004.
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
struct month {
int beginning;
int end;
int totalDays;
};
int choice;
void getDate(int day)
{
int date;
month January = { 1, 31, 31 };
month February = { 32, 61, 28 };
month March = { 62, 93, 31 };
month April = { 94, 124, 30 };
month May = { 125, 156, 31 };
month June = { 157, 187, 30 };
month July = { 188, 219, 31 };
month August = { 220, 251, 31 };
month September = { 252, 282, 30 };
month October = { 283, 314, 31 };
month November = { 315, 345, 30 };
month December = { 346, 365, 31 };
if ((day >= 1) && (day <= 365))
{
if((day >= January.beginning) && (day <= January.end)) //month is January
{
date = day ;
cout << date;
cout << " Jsnuary 2004 " <<endl;
cout << " Do you have more to do? "<<endl;
cin >> choice;
system("pause");
}
else if((day >= February.beginning) && (day <= February.end)) //month is February
{
date = day - 32;
cout << date;
cout << " February 2004 " <<endl;
system("pause");
}
else if((day >= March.beginning) && (day <= March.end)) //month is March
{
date = day - 62;
cout << date;
cout << " March 2004 " <<endl;
system("pause");
}
else if((day >= April.beginning) && (day <= April.end)) //month is April
{
date = day - 94;
cout << date;
cout << " APril 2004 " <<endl;
system("pause");
}
else if((day >= May.beginning) && (day <= May.end)) //month is May
{
date = day - 125;
cout << date;
cout << " May 2004 " <<endl;
system("pause");
}
else if((day >= June.beginning) && (day <= June.end)) //month is June
{
date = day - 157;
cout << date;
cout << " June 2004 " <<endl;
system("pause");
}
else if((day >= July.beginning) && (day <= July.end)) //month is JUly
{
date = day - 188;
cout << date;
cout << " July 2004 " <<endl;
system("pause");
}
else if((day >= August.beginning) && (day <= August.end)) //month is August
{
date = day - 220;
cout << date;
cout << " August 2004 " <<endl;
system("pause");
}
else if((day >= September.beginning) && (day <= September.end)) //month is September
{
date = day - 252;
cout << date;
cout << " September 2004 " <<endl;
system("pause");
}
else if((day >= October.beginning) && (day <= October.end)) //month is October
{
date = day - 283;
cout << date;
cout << " OCtober 2004 " <<endl;
system("pause");
}
else if((day >= November.beginning) && (day <= November.end)) //month is November
{
date = day - 315;
cout <<date;
cout << " November 2004 " <<endl;
system("pause");
}
else if((day >= December.beginning) && (day <= December.end)) //month is December
{
date = day - 346;
cout << date;
cout << " December 2004 " <<endl;
system("pause");
}
else
{
cout << "Error!!! Please refine j00 input!" << endl;
system("pause");
}
}
}
int main()
{
int day;
cout << "PLease enter a number between 1 and 365!" << endl;
cin >> day;
getDate(day);
return 0;
}mabufo wrote:then again I must have set the math problem that gets the date up incorrectly.
well, back to R&D for me!
Stuck wrote:It compiles without error under Borland IDE 5.2
daysmonth[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
totaldays[] = { 1, 32, 62, 94, 125,157,188,220,252,283,315,346};
switch(day)
{
case 1: cout << "st"; break;
case 2: cout << "nd"; break;
case 3: cout << "rd"; break;
case 21: cout << "st"; break;
case 22: cout << "nd"; break;
case 23: cout << "rd"; break;
case 31: cout << "st"; break;
default: cout << "th"; break;
}
switch(day)
{
case 1:
case 21:
case 31:
cout << "st";
break;
etc.struct MONTH
{
char *monthName;
int numDays;
}
int DateFunc(int a, int b, int c)
{
int d;
d = a - b;
day = c - d;
return day;
}month February = { 32, 61, 28 };Users browsing this forum: No registered users and 1 guest