| | |
"expect a constant expression"
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
You know, I just found out that IT IS POSSIBLE to do it my way, but it wont accept the way I calculate the "int"
I tested it with this:
So, in light of this new information. How do I BEST CALCULATE that?
like, rounding up without having to convert to double?
I also think I need a lecture on casts, 'cause maybe I'm not handling them right...
I tested it with this:
cpp Syntax (Toggle Plain Text)
const int test1 = 10/5; //even number without having to round up double test2_calc = (double)10/(double)5; const int test2 = (int)test2_calc; char mychar[test1][ANOTHER_CONSTANT]; //Works char mychar[test2][ANOTHER_CONSTANT]; //Doesn't work
So, in light of this new information. How do I BEST CALCULATE that?
like, rounding up without having to convert to double?
I also think I need a lecture on casts, 'cause maybe I'm not handling them right...
Last edited by ShadowScripter; Apr 17th, 2009 at 10:01 pm.
Why are you using old casting ?
It's a better practice to use the new casting operators to do conversion between datatypes:
instead of the old ones:
•
•
•
•
double test2_calc = (double)10/(double)5; const int test2 = (int)test2_calc;
double num = 5.23; int num2 = static_cast<int>(num);
double num = 5.23;
int num2 = (int)num; Last edited by tux4life; Apr 19th, 2009 at 7:41 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
See here why: http://www.informit.com/guides/conte...lus&seqNum=134
Boils down to C-style casts being static_casts or reinterpret_casts. But I never got reinterpret_cast to work anyway.
Boils down to C-style casts being static_casts or reinterpret_casts. But I never got reinterpret_cast to work anyway.
See, now this is why I love these forums! You are all willing to share your knowledge (albeit most knowledge passed on to you by others as well). I didn't know about static_cast, because I rely most of my work on the C++ Beginner's Guide written by the Microsoft Corporation, I guess it's not up to date... either that or I missed static_cast entirely 
Still tho, the answer to my original question remains unclear, well, I did get some suggestions from Clockowl about vectors, but they were much too confusing and I would ask you to explain them in a more easier way for me to understand, but that is for another thread.
At one time I thought about using pointers, during these 2 days since I posted my problem I have grown to learn more about the power of pointers. I managed to create a pretty good converter function, more specifically a Char To String, AND, a String to Char! I don't know if it already exists or is unnecessary, but it sure was fun!
Where was I?... right, thanks to the both of you, especially Clockowl! You seem very active. +rep (if my rep matters)

Still tho, the answer to my original question remains unclear, well, I did get some suggestions from Clockowl about vectors, but they were much too confusing and I would ask you to explain them in a more easier way for me to understand, but that is for another thread.
At one time I thought about using pointers, during these 2 days since I posted my problem I have grown to learn more about the power of pointers. I managed to create a pretty good converter function, more specifically a Char To String, AND, a String to Char! I don't know if it already exists or is unnecessary, but it sure was fun!

Where was I?... right, thanks to the both of you, especially Clockowl! You seem very active. +rep (if my rep matters)
Last edited by ShadowScripter; Apr 19th, 2009 at 11:07 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Major Problem with Doubly linked list program
- Next Thread: Trouble with multi-file program
| Thread Tools | Search this Thread |
api application array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






