Page:
Home > Help Needed / General Tech Chat > anyone write C++?

Joe C

User Avatar

12307 Posts
Member #: 565
Carlos Fandango

Burnham-on-Crouch, Essex

I have to write a bit of C++ code to convert ????? seconds into Hrs:Min:Sec format,

I think I may have cracked it but am not sure the intergers are working as I think they are, I've looked on line for converters but cant find any.

can any one confirm if this looks right?





On 28th Aug, 2011 Kean said:
At the risk of being sigged...

Joe, do you have a photo of your tool?



http://www.turbominis.co.uk/forums/index.p...9064&lastpost=1

https://joe1977.imgbb.com/



BadgerBaiter

499 Posts
Member #: 2257
Senior Member

Brighton

I think that looks right to me.
I only just started C++ this semester though, so there is chance I am wrong!

http://www.jolyonway.com


Joe C

User Avatar

12307 Posts
Member #: 565
Carlos Fandango

Burnham-on-Crouch, Essex

lol i'm only a couple of weeks in too,

cheers!

On 28th Aug, 2011 Kean said:
At the risk of being sigged...

Joe, do you have a photo of your tool?



http://www.turbominis.co.uk/forums/index.p...9064&lastpost=1

https://joe1977.imgbb.com/



Rob H

4314 Posts
Member #: 700
Formerly British Open Classic

The West Country

It's been about 10 years since I wrote any code so I'm very rusty but it looks about right, does it compile & run? The only thing I'm not sure about is whether or not long the correct variable type would integer be better.

Isambard Kingdom Brunel said:
Nothing is impossible if you are an Engineer


GaryOS

User Avatar

1424 Posts
Member #: 2810
Formally spanner181187

Dublin, Ireland

It looks OK to me too. I haven't done any in 3 years though. I'll stare at it for a while longer and see if I get anywhere

On 12th Nov, 2009 Paul S said:

I think Gary OS has taken over my role as the forum smart arse *happy*


On 30th Apr, 2010 Rod S said:
Gary's description is best


BadgerBaiter

499 Posts
Member #: 2257
Senior Member

Brighton

I ve just been made aware that I need to write a specification for a program that I have to write.
We all thought it was due for the end of the week. oops.
Doing a unit conversion program; distance, mass, volume etc etc.
Its due for 8am.
oops.

http://www.jolyonway.com


rubicon

User Avatar

3756 Posts
Member #: 1709
I like granny porn.

LONDONSHIRE

WTF....

On 2nd Oct, 2009 Vegard said:


On 1st Oct, 2009 Jimster said:
I bet my first wank came quicker than your first mini turbo


These new modern turbos with their quick spool up time, would make the competition harder.


On 15th Aug, 2011 robert said:
phew!!! thank you brett for smashing in my back doors .( not something i imagined writing... EVER)


alpa

520 Posts
Member #: 2093
Post Whore

Grenoble, France

remove your last % 60 operation and check instead that seconds are always < 60. If it happens then you messed up.
In theory you could use
assert(seconds < 60)
But assert() is a shit because it makes an abort() of the program, it kills it right away.

Another point: time is never negative, right ? So don't use signed types for it (long is actually long int), especially because % operation gives surprising results on signed values.
In theory you should check the validity of what users have typed as input, in your case they can input a negative number.

Edited by alpa on 23rd Mar, 2010.

std 998 A+, g295, MD266, RHF4, 109hp @0.8bar/5400rpm


apbellamy

User Avatar

16540 Posts
Member #: 4241
King Gaycharger, butt plug dealer, Sheldon Cooper and a BAC but generally a niceish fella if you dont mind a northerner

Rotherham, South Yorkshire

The code is correct as far as c++, but as others have said the maths might be wrong. The easyest way to do something like this is to work out the equation on paper with numbers, then translate the numbers into variables, then just move it into your code.

Out of curiosity, why have they got you learing c++? That went out with the arc, you should be doing c# these days. It has proper object orientation and is much much easier to learn (I am a novice at best).

On 11th Feb, 2015 robert said:
i tried putting soap on it , and heating it to brown , then slathered my new lube on it

*hehe!*


alpa

520 Posts
Member #: 2093
Post Whore

Grenoble, France

apbellamy, most of industrial applications are written in C and C++, especially those sold for more than $1000 per license. When you use some c# or ruby or any other flavor of the the modern trend there is quite often something else running behind your application, and this one was written in C/C++ (I write in C/C++ for living).
Understanding of the C/C++ programming is the base of a good programming in other languages, at least to avoid reproducing common mistakes of the C++ programming.

Edited by alpa on 23rd Mar, 2010.

std 998 A+, g295, MD266, RHF4, 109hp @0.8bar/5400rpm


BadgerBaiter

499 Posts
Member #: 2257
Senior Member

Brighton

i may have to pick your brains in the future Alpa. I apologise in advance :p

http://www.jolyonway.com


Joe C

User Avatar

12307 Posts
Member #: 565
Carlos Fandango

Burnham-on-Crouch, Essex

Thanks Alpa,

Good point on the unsigned variabes :)

you also made me think about how I was using the modulus function, I have now don the calculations a different way and they seem to be coming out correct, (they wern't before).

if anyone's interested here it is now.




On 28th Aug, 2011 Kean said:
At the risk of being sigged...

Joe, do you have a photo of your tool?



http://www.turbominis.co.uk/forums/index.p...9064&lastpost=1

https://joe1977.imgbb.com/



Joe C

User Avatar

12307 Posts
Member #: 565
Carlos Fandango

Burnham-on-Crouch, Essex

Andy,

I'm leaning C++ as I'm looking to start doing stuff with PIC's in C, apparently they are similar enough to learn either then the other later on.

also the C++ should be useful for interfacing with the pic's from a pc.

or that's what I've been told anyway...

On 28th Aug, 2011 Kean said:
At the risk of being sigged...

Joe, do you have a photo of your tool?



http://www.turbominis.co.uk/forums/index.p...9064&lastpost=1

https://joe1977.imgbb.com/



jbelanger

1267 Posts
Member #: 831
Post Whore

Montreal, Canada

That definitely looks better (and correct).

Jean

http://www.jbperf.com/


alpa

520 Posts
Member #: 2093
Post Whore

Grenoble, France

Well now that you made the final version: usually you won't do this way because you'll want to translate the wall clock second number (# of seconds from 1970) you got from the system. And you'll do that using standard C functions.
PIC: the crappiest microcontroller I've ever seen. Try using something else if you want to learn, just to know what a MCU should look like. Say 8051 or any Motorola or AVR (Atmel). PICs used to be cheap but I suspect they became more expensive since they won market shares. And they are still a crap.

Edited by alpa on 23rd Mar, 2010.

std 998 A+, g295, MD266, RHF4, 109hp @0.8bar/5400rpm


Carl S
Forum Mod

User Avatar

1927 Posts
Member #: 1761
Stalker

Bristol

Here it is in java :)

import java.util.*;
public class SecondsConvert
{
public static void main(String[] args)
{
Scanner kybd = new Scanner(System.in);
int secondsIn, secondsOut, minutes, hours;
System.out.println("Please enter the number of seconds to convert: ");
secondsIn = kybd.nextInt();
hours = secondsIn / 3600;
minutes = (secondsIn % 3600) / 60;
secondsOut = (secondsIn % 3600) % 60;
System.out.println("The total time is: " + hours + ":" + minutes + ":" + secondsOut);
}
}


jbelanger

1267 Posts
Member #: 831
Post Whore

Montreal, Canada

Carl, you don't need the modulo 3600 when computing secondsOut.

Alpa, the Motorola are now Freescale MCUs.

Jean

http://www.jbperf.com/


Carl S
Forum Mod

User Avatar

1927 Posts
Member #: 1761
Stalker

Bristol

I wrote that about 2 years ago Jean, I just remembered that I did a similair thing, so cut and pasted it from my old code archive!

It could probably be optimised but it's not much use to me any more :)


alpa

520 Posts
Member #: 2093
Post Whore

Grenoble, France

Yes I know. Philips is NXP, Siemens is Infineon, SGS Thomson is STMicro. Fairchild MOS and Mostec and many others are dead, I've heard that somewhere :) . Intel is still Intel, I wonder why.

std 998 A+, g295, MD266, RHF4, 109hp @0.8bar/5400rpm


AlexB
Site Admin

User Avatar

6295 Posts
Member #: 1
The boring bloke who runs this place.

Berkshire

Games are all still written in C++, too.

Home > Help Needed / General Tech Chat > anyone write C++?
Users viewing this thread: none. (+ 1 Guests)  
To post messages you must be logged in!
Username: Password:
Page: