The Mother Board forums. Free tech support, motherboard ID, and more.
It is currently Mon Sep 24, 2018 11:45 pm

All times are UTC - 8 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Basic math brainfart
PostPosted: Mon Aug 01, 2005 4:06 pm 
Black Belt
Black Belt

Joined: Tue Oct 01, 2002 2:06 pm
Posts: 921
Location: Illinois
Ok, I'm trying to brush up on my C++ (haven't touched it in over 5 years) not for anything in particular, just for my own enjoyment. Well, I haven't taken a math class in 5+ years as well (got up to calculus) and this is probably a really simple question with a very simple answer and for the life of me, I can't figure it out. I'm reading a book and one of the exercises asks for me to convert inches to feet and inches and to use a const as the conversion factor. I can't figure out the conversion factor.

Some (pseudo)code:

const conversion_factor_I_can't_figure_out

//now this is what *I* want to do, just generic code, not what I'm really gonna do ;)

int totalInches = 75; //(6 foot 3 inches)
int feet = totalInches / 12; //drops the decimal of .25 and feet comes to 6
int inches = totalInches % 12; //modular, drops the remainder of 3 into inches

Maybe I'm going about this all wrong, but to me, what I typed in would be correct and maybe the author just wants something simple like:

const int ONEFOOT = 12;

I'm thinking that a const cannot be a function or a formula. That would better be handled by a #define but then again I haven't been familiar with C++ for quite a while.

I think what I'm doing is right, but if someone wants to correct me, feel free, it's what I'm looking for :wink:

I can post the question too if need be.

Reply with quote  
 Post subject:
PostPosted: Mon Aug 01, 2005 4:20 pm 
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2741
Location: Milwaukee - Wisconsin
the way you're doing it is entirely correct. that should work for ya.

still need:
int total = feet + inches;

a const cannot be a function or formula (as i can remember....).

moving into defines and such seems a little bit over-the-top IMHO.


Lian Li Lancool First Knight Series PC-K59W
Intel Core i7-960 Bloomfield 3.2GHz
EVGA X58 FTW3 132-GT-E768-TR
G.SKILL Ripjaws Series 12GB (3 x 4GB)
Crucial M4 128gb SATAIII SSD x2
Crucial M4 256gb SATAIII SSD
OCZ Saber 1000 960GB Enterprise SSD
Corsair Professional Series HX850 PSU
Dell UltraSharp U2713HM 27" w/drop ceiling mount
Logitech G930 7.1 Headset
Logitech G402 Hyperion Fury

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group