hi all,
i'm wondering is there any other alternative to do a timestamp which consists of date and time!! below is a program i've created but its too long and to large i would like to know other way to do it can anyone help me?
here is some part of the program i've created its impossible to show u guys the whole program as ive copy it to save in a notepad and its file is 64kb!!please tell me if there is other alternative to do this program??
thanks in advance!!appreciate your help??hope to get your good news soon!!
regrads andrew.
god bless ya all
13 2208
Hi. This does seem to be a very long winded method for getting a user to input a date. What is the purpose of the code?
Hi. This does seem to be a very long winded method for getting a user to input a date. What is the purpose of the code?
thanks willa for replying
yes indeed its a long winded method that is why im trying to find out is there any other way u can do it!!
the program basically need the user to keyin the date and time in ddmmyyhhnnss(d=day,m=month,y=year,h=hour,n=min,s=s ec) where the day must have a condition which is 01-31/28/30 and soo on for the rest therefore the oni way i can think off is using switch case which turn out to be way too long!!so is there any other way to do this??
thanks for ur HELP appreciate it alots!!
There seems to be significant repetition in the code. As soo as you need to write the samething several times, consider using a function.
You may like to create a function that selects number of days in the month viz -
int daysInMonth(int month, int yr)
-
{
-
switch(month)
-
{
-
case 1:
-
case 3:
-
case 5:
-
case 7:
-
case8:
-
case 10:
-
case 12:
-
return 31;
-
case 2:
-
return daysInFebThisYear(yr); //you'll need to implement this method
-
case 4:
-
case 6:
-
case 9:
-
case 11;
-
return 30;
-
default:
-
printf("Can't identify month");
-
return 0;
-
}
-
}
-
This can replace your case statement included.
I'm not entirely sure why you bother analyzing things about the year, unless this is a requirem,ent....
There seems to be significant repetition in the code. As soo as you need to write the samething several times, consider using a function.
You may like to create a function that selects number of days in the month viz -
int daysInMonth(int month, int yr)
-
{
-
switch(month)
-
{
-
case 1:
-
case 3:
-
case 5:
-
case 7:
-
case8:
-
case 10:
-
case 12:
-
return 31;
-
case 2:
-
return daysInFebThisYear(yr); //you'll need to implement this method
-
case 4:
-
case 6:
-
case 9:
-
case 11;
-
return 30;
-
default:
-
printf("Can't identify month");
-
return 0;
-
}
-
}
-
This can replace your case statement included.
I'm not entirely sure why you bother analyzing things about the year, unless this is a requirem,ent....
hi deman,
thanks for this info it does help me alot in this method!!LOL wondering why can't i think of this method!!looks like there is no other way besides switch case and if else condition to do this program rite??ok then thanks for ur help!!appreciate it lots!!
but how to calculate the month of feb? when there is a leap year and not leap year how do i calculate it??
thanks alot!!
From what I remember,
You have a year y.
y is a leap year if y is divisble by 4.
BUT, y is NOT a leap year if it is divisible by 100.
BUT, y IS a leap year if it is divisible by 400.
So 1996 is a leap year because it IS divisible by 4.
2000 is a leap year because it is divisible by 400.
1900 is NOT a leap year because it is divisible by 100 BUT NOT 400.
2001 is NOT a leap year because it is not divisible by 4.
Can you develop an algorithm for this?
From what I remember,
You have a year y.
y is a leap year if y is divisble by 4.
BUT, y is NOT a leap year if it is divisible by 100.
BUT, y IS a leap year if it is divisible by 400.
So 1996 is a leap year because it IS divisible by 4.
2000 is a leap year because it is divisible by 400.
1900 is NOT a leap year because it is divisible by 100 BUT NOT 400.
2001 is NOT a leap year because it is not divisible by 4.
Can you develop an algorithm for this?
hi ganon,
oh yea thanks for the information i needed!!
i'll try to develop an algorithm for it!!
if i still have prob wif that i'll be back!!haha~~
thanks
hi all members of thescripts
i've done some part of the program but it appears error on case 8 and case 9!!don't know what is the problem!!and i've done somehting which in switch case but not sure can it work please help me!! below is the program i've created for timestamp thanks to the idea of deman!!
i declare month as char month[2] -
cout<<"Please enter the current month:"<<endl;
-
month: cin>>month;
-
if(strlen (month)==2)
-
{
-
for(int i=0; i<=1; i++)
-
{
-
if(!isdigit(month[i]))
-
{
-
cout<<"Invalid input for month!!"<<endl;
-
cout<<"Please re-enter two digit of the current month"<<endl;
-
goto month;
-
}
-
}
-
-
switch(month)
-
{
-
case 01:
-
case 03:
-
case 05:
-
case 07:
-
case 08:
-
case 10:
-
case 12:
-
cout<<"Has 31 days"<<endl;break;
-
case 04:
-
case 06:
-
case 09:
-
case 11:
-
cout<<"Has 30 days"<<endl;break;
-
case 02:
-
cout<<"Has 28 and 29 days"<<endl;break;
-
default:
-
cout<<"Invalid month"<<endl;break;
-
}
-
}
-
else
-
{
-
cout<<"You have entered more than 2 digit or other character"<<endl;
-
cout<<"Please re-enter two digit of the current month"<<endl;
-
goto month;
-
}
-
Question:
1)can i declare case as case 01?(i need 2 digit for month dat's why i do this is it possible?)
2)there is an error on case 8 and 9 saying that illegal digit ' 8' for base '8' same as 9. WHY?
thanks for ur help!!
Well, you can't use a switch statement with an array. switch requires 1 numeral type, not a pointer (which is what month is right now). Why are you using a char array? Why not an integer?
Well, you can't use a switch statement with an array. switch requires 1 numeral type, not a pointer (which is what month is right now). Why are you using a char array? Why not an integer?
if i use an integer array if can do the string compare which i've done so i need to use a char array. thanks for the switch statement. is there any other way to do if i need to have 2digit output coz i need to print out 01 for jan instead of just 1?
and do u know why it have the error on case 8 and 9?
thanks ganon
One (simple) way to do it, would be to do your checks and allocate an integer value based on this....If you can tell whether a char is a digit, you should be able to returbn which one. make a method to return the value of teh digit if it is one, or return a negative number if it isn't, then you can modify your code..... -
.if(strlen (month)==2)
-
{
-
int temp = -1;
-
int monthVal = 0;
-
for(int i=0; i<=1; i++)
-
{
-
temp = getDigit(month[i]);
-
if(temp < 0)
-
{
-
cout<<"Invalid input for month!!"<<endl;
-
cout<<"Please re-enter two digit of the current month"<<endl;
-
goto month
-
}
-
else
-
{
-
monthVal = monthVal* 10 + temp;
-
}
-
}
-
-
//continue with rest of code.....
-
One (simple) way to do it, would be to do your checks and allocate an integer value based on this....If you can tell whether a char is a digit, you should be able to returbn which one. make a method to return the value of teh digit if it is one, or return a negative number if it isn't, then you can modify your code..... -
.if(strlen (month)==2)
-
{
-
int temp = -1;
-
int monthVal = 0;
-
for(int i=0; i<=1; i++)
-
{
-
temp = getDigit(month[i]);
-
if(temp < 0)
-
{
-
cout<<"Invalid input for month!!"<<endl;
-
cout<<"Please re-enter two digit of the current month"<<endl;
-
goto month
-
}
-
else
-
{
-
monthVal = monthVal* 10 + temp;
-
}
-
}
-
-
//continue with rest of code.....
-
hi ganon,
sorry to disturb u again but when i use your way it shows error. BTW what is getdigit? isit same as isdigit? i have error on that shows undeclare.
ive tried another way but dunno it works anot? can u help me?
is almost the same problem with the month which i need to put 0 in the front of every single digit.
question:
i declare as integer because i'm using swith case but in the case i convert it into char because i'm using stringcopy to make the output that i need!!so is this the right way? am i missing some steps? coz i still can't get the output that i want.
below is my program: -
//hour declared as integer
-
cout<<"Please enter the current hour:"<<endl;
-
hour: cin>>hour;
-
if((hour)>0 && (hour)<=24)
-
{
-
switch(hour)
-
{
-
case 1:
-
{
-
char hour[2]; //converting into char
-
strcpy(hour,"01");
-
-
goto nama; //con't on the program
-
break;
-
}
-
thanks for those who help me!!sorry for the trouble i'm kinda new to c++ so alot of things are yet to learn from you all!! thanks in a millon!!
regrads andrew
WOW the code is in a mess!!
here is a better one!! -
cout<<"Please enter the current hour:"<<endl;
-
hour: cin>>hour; //declare hour as integer because using switch case
-
if((hour)>0 && (hour)<=24)
-
{
-
switch(hour)//there are 9 cases
-
{
-
case 1:
-
{
-
-
char hour[2];//converting integer into char because using stringcopy
-
strcpy(hour,"01");
-
-
goto nama;//proceed to the rest of the program
-
break;
-
}
-
sorry the intention was to show you an algorithm.....I was suggesting that you could create a method called "getDigit" which wopuld return the value of the entered sequence....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: perplexed |
last post by:
How do you convert a user inputted date to a unix timestamp before
insterting it into your database? I have a form, with a textfield for
a date that the user inputs in the format mm-dd-yyyy and...
|
by: rong.guo |
last post by:
Hello Group,
I am having a really weird problem... Can anyone tell the difference
between Query 1 and Query 2 below? Why Query 2 excludes '2/28/2005'?
Many thanks!
create table a...
|
by: Steffen Ramlow |
last post by:
Hi there,
is there any way besides a trigger to create a unique number for a column in
a "insert into... select from" statement?
Thx, sr
--
Kein Plan überlebt die erste Feindberührung.
|
by: Russell Smith |
last post by:
Timestamps support infinity. However if appears dates do not.
When timestamps are cast to dates, there is no output. Is this an acceptable option or not?
Below are a number of examples...
|
by: Mal Ball |
last post by:
I hope I have the right forum for this question. I have an existing Windows
application which uses a SQL Server database and stored procedures. I am now
developing a web application to use the same...
|
by: JJ |
last post by:
How do I set one field to have the updated timestamp, and another to have
the created timestamp?
I want to do this directly from code generated from DB Designer if
possible?!
JJ
|
by: robert |
last post by:
I'm told "select distinct on" or even "select distinct" is inefficient
because it selects then discards rows.
However, I'm stumped to find an alternative to this query :
select distinct on...
|
by: kanwal |
last post by:
Hi,
I have millions of records in my xxxxx table in mysql. And I have a
column of time in which I have stored the timestamp using php time()
function.
Now I wanna write an SQL query to fetch...
|
by: Bill David |
last post by:
SUBJECT: How to make this program more efficient?
In my program, a thread will check update from server periodically and
generate a stl::map for other part of this program to read data from....
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |