The Mother Board

Motherboards.org forums. Free tech support, motherboard ID, and more.
It is currently Tue Aug 21, 2018 11:51 am

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 
Offline
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:

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:

Code:
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.


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

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

still need:
Code:
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.

-Roach

_________________
Lian Li Lancool First Knight Series PC-K59W
Intel Core i7-960 Bloomfield 3.2GHz
EVGA X58 FTW3 132-GT-E768-TR
EVGA GeForce GTX 1070 FTW GAMING ACX 3.0
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
DBPOWER RGB LED Keyboard
Logitech G402 Hyperion Fury


Top
 Profile  
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:  
cron
Powered by phpBB® Forum Software © phpBB Group