corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Help desperatly needed from c programmers


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Help desperatly needed from c programmers
kerzo
Member

Registered: 10th Nov 02
Location: Norn Iron
User status: Offline
19th Nov 03 at 15:45   View User's Profile U2U Member Reply With Quote

i am confused at who to go about this question for a coursework assignment and any help or even a program would be brilliant, here is the question

Construct a ‘C’ program that subtracts one time from another. You may assume that times are expressed in terms of a number of hours and a number of minutes and are in 24-hour format. For example, subtracting 1 hour 30 minutes from 1 hour 0 minutes (representing 010) should result in 23:30 being displayed (i.e. 11:30pm the previous day). The user will enter four values (the hours and minutes of each of the two times) and the program should then output the result of the subtraction in 24-hour format.

Mikorsa16v
Member

Registered: 2nd Sep 02
Location: Burgess Hill, West Sussex
User status: Offline
19th Nov 03 at 15:49   View User's Profile U2U Member Reply With Quote

right firstly you need to split up the hours and the mins, as two seperate integers and then set the 'limit' as static variables to both, i.e. the limit for hours is 24, and the limit for the mins is 60.

i was gonna say have two classes one for hours and one for mins, but C isnt OO thinking of c++.

i havent coded in C for a year now! so can only help on the structure really, as i look at past assignments lol
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
19th Nov 03 at 15:53   View Garage View User's Profile U2U Member Reply With Quote

Easier to convert the dates to a standardised timestamp (number of seconds since 1900) and then perform a simple subtraction. You can then convert back to the real date answer...
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
19th Nov 03 at 15:55   View Garage View User's Profile U2U Member Reply With Quote

Or construct an array for hours and an array for minutes... you could then do the maths on the array indices and return the correct value...
kerzo
Member

Registered: 10th Nov 02
Location: Norn Iron
User status: Offline
19th Nov 03 at 22:57   View User's Profile U2U Member Reply With Quote

oh so confused!!!
John_C
Member

Registered: 5th Mar 03
Location: South east, Bromley
User status: Offline
19th Nov 03 at 23:32   View User's Profile U2U Member Reply With Quote

c sucks
can't get my head round it
kerzo
Member

Registered: 10th Nov 02
Location: Norn Iron
User status: Offline
19th Nov 03 at 23:41   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by John_C
c sucks
can't get my head round it


same as me pity i have another few weeks of it then onto java
John_C
Member

Registered: 5th Mar 03
Location: South east, Bromley
User status: Offline
19th Nov 03 at 23:42   View User's Profile U2U Member Reply With Quote

low level bs!

i'm meant 2 b doin c++ tonight as well, thats goin marginally better but not great
kerzo
Member

Registered: 10th Nov 02
Location: Norn Iron
User status: Offline
19th Nov 03 at 23:49   View User's Profile U2U Member Reply With Quote

16/40 in a class test i got
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
19th Nov 03 at 23:56   View Garage View User's Profile U2U Member Reply With Quote

One sec...
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
19th Nov 03 at 23:59   View Garage View User's Profile U2U Member Reply With Quote

Apologise for rushed code but it should do the job... there are neater ways of doing this I just haven't got a function reference to hand...

code:

#include <stdio.h>
void main() {
int result, time1_h, time1_m, time2_h, time2_m;

printf("Enter 1st time hour: ");
scanf("%d", &time1_h);
printf("Enter 1st time mins: ");
scanf("%d", &time1_m);
printf("Enter 2nd time hour: ");
scanf("%d", &time2_h);
printf("Enter 2nd time mins: ");
scanf("%d", &time2_m);

result = ((60*time1_h) + time1_m) - ((60*time2_h) + time2_m);

// Fix if time becomes 'yesterday'
while (result < 0) {
result = result + 1440; // Number of minutes in a day
}

// Output result
printf("Time (1st - 2nd): %02d:%02d\n",(result / 60), (int)(result % 60));
}

Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:05   View Garage View User's Profile U2U Member Reply With Quote

cout << etc is C++...
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:06   View Garage View User's Profile U2U Member Reply With Quote

C and C++ are not the same
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:08   View Garage View User's Profile U2U Member Reply With Quote

I should make deletion of posts say "comment withdrawn"
John_C
Member

Registered: 5th Mar 03
Location: South east, Bromley
User status: Offline
20th Nov 03 at 00:09   View User's Profile U2U Member Reply With Quote

fekin pointers
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:09   View Garage View User's Profile U2U Member Reply With Quote

Arghhh I'm having a convo with myself
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
20th Nov 03 at 00:11   View User's Profile U2U Member Reply With Quote

the initial joke of 'Your point?' was the fact you were talking to yourself... I had already removed mine, I know they're different - but assumed he said he was doing C++ not C, oops.

Don't put 'Post deleted' its more fun this way
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:12   View Garage View User's Profile U2U Member Reply With Quote

quote:
Originally posted by John_C
fekin pointers


They're ok once you get your head round the idea of memory and allocation etc... def worth learning properly though or else when you come to harder examples you really get stuck...
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:12   View Garage View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
the initial joke of 'Your point?' was the fact you were talking to yourself... I had already removed mine, I know they're different - but assumed he said he was doing C++ not C, oops.

Don't put 'Post deleted' its more fun this way


I should have just quoted you
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
20th Nov 03 at 00:12   View User's Profile U2U Member Reply With Quote

yes =]
kerzo
Member

Registered: 10th Nov 02
Location: Norn Iron
User status: Offline
20th Nov 03 at 00:17   View User's Profile U2U Member Reply With Quote

oh my god thank you

i would ask for more but would that just be too greedy!!!
Tim
Site Administrator

Avatar

Registered: 21st Apr 00
User status: Offline
20th Nov 03 at 00:17   View Garage View User's Profile U2U Member Reply With Quote

No probs you wouldn't believe how bored I was

Sorry but that's ya £12.50's worth


[Edited on 20-11-2003 by Tim]
kerzo
Member

Registered: 10th Nov 02
Location: Norn Iron
User status: Offline
20th Nov 03 at 01:32   View User's Profile U2U Member Reply With Quote

at least i got good value from it

cheers tim
Dan B
Member

Registered: 25th Feb 01
User status: Offline
20th Nov 03 at 01:45   View User's Profile U2U Member Reply With Quote

Now there's a different usage for the whole Premium Member thing......don't suppose you fancy doing my C coding, Tim? It'll only take you about 2 months!

I'll buy Premium Membership if you do!
Jason
Member

Registered: 5th Aug 03
Location: Northern Ireland
User status: Offline
20th Nov 03 at 01:53   View User's Profile U2U Member Reply With Quote

kerzo u'll love j++

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Joke Happy_2008 General Chat 4 1209
15th Oct 03 at 19:25
by chris_uk
 
Combat Side Skirts (now with more pics) Paul_J Parts Offered 8 1316
19th Oct 04 at 12:13
by Paul_J
 
alpine digital amp over-current RobHayes Help Zone, Modification and ICE Advice 13 1181
15th Sep 04 at 16:49
by RobHayes
 
Insurance - Help Needed ASAP Danny P General Chat 4 960
23rd Mar 05 at 21:42
by Danny P
 
Any programmers out there? Cosmo Geek Day 16 1870
28th Oct 05 at 16:46
by James
 

Corsa Sport » Message Board » Off Day » Geek Day » Help desperatly needed from c programmers 28 database queries in 0.0166800 seconds