Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » General Discussions » General Discussion » I Learn Some Basic C++!
Re: I Learn Some Basic C++! [message #392285 is a reply to message #392062] Thu, 25 June 2009 16:14 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
SSnipe wrote on Thu, 25 June 2009 22:19

What I mean is how do you know there to put the variable, and then the other numbers, and which ones go inside ther brackets


jnz wrote on Wed, 24 June 2009 18:00


Read up on BODMAS (or BADMAS).

Re: I Learn Some Basic C++! [message #392381 is a reply to message #391886] Fri, 26 June 2009 09:58 Go to previous messageGo to next message
CarrierII is currently offline  CarrierII
Messages: 3804
Registered: February 2006
Location: England
Karma: 0
General (3 Stars)

I imagine there's a good wikipedia entry... oh yes:

http://en.wikipedia.org/wiki/BODMAS

We didn't keep mentioning BODMAS for no reason.


Renguard is a wonderful initiative
Toggle Spoiler
Re: I Learn Some Basic C++! [message #392393 is a reply to message #391886] Fri, 26 June 2009 10:27 Go to previous messageGo to next message
cmatt42 is currently offline  cmatt42
Messages: 2057
Registered: July 2004
Karma: 0
General (2 Stars)
Also known as PEMDAS in the US.

Re: I Learn Some Basic C++! [message #392395 is a reply to message #392393] Fri, 26 June 2009 10:49 Go to previous messageGo to next message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
cmatt42 wrote on Fri, 26 June 2009 10:27

Also known as PEMDAS in the US.

Thats wat i learned it as..
Re: I Learn Some Basic C++! [message #392448 is a reply to message #391886] Fri, 26 June 2009 19:18 Go to previous messageGo to next message
HTT-Bird is currently offline  HTT-Bird
Messages: 11
Registered: June 2009
Karma: 0
Recruit
SSnipe: Grab "Accelerated C++" by Andrew Koenig and Barbara Moo. That should get you much further than anything I can post in this thread. Once you've worked through that book, you will have a good enough grasp of the language to start playing with Rene-coding.

@SK: Go read "The String Formatters of Manor Farm" by Herb Sutter. That, and we're getting varadic templates in C++0x, so expect to see something >>>> printf soon. Hint:
#include <cstdio>
int main()
{
  const char* bad = "this will blow up";
  int very = 42;
  std::printf("%s%d\n", very, bad);
  return 0;
} 


With a varadic-template-enabled version of printf, you'd get a compiler error saying "can't convert int to const char*" not Undefined Behavior (translation: crash bang boom) at runtime.
Re: I Learn Some Basic C++! [message #392518 is a reply to message #392448] Sat, 27 June 2009 06:58 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
HTT-Bird wrote on Sat, 27 June 2009 03:18

SSnipe: Grab "Accelerated C++" by Andrew Koenig and Barbara Moo. That should get you much further than anything I can post in this thread. Once you've worked through that book, you will have a good enough grasp of the language to start playing with Rene-coding.

@SK: Go read "The String Formatters of Manor Farm" by Herb Sutter. That, and we're getting varadic templates in C++0x, so expect to see something >>>> printf soon. Hint:
#include <cstdio>
int main()
{
  const char* bad = "this will blow up";
  int very = 42;
  std::printf("%s%d\n", very, bad);
  return 0;
} 


With a varadic-template-enabled version of printf, you'd get a compiler error saying "can't convert int to const char*" not Undefined Behavior (translation: crash bang boom) at runtime.


Even more reason to be a stupid programmer! I've had my fair share of mismatched format strings, but due to the fact your program will blow up at runtime and the debugger usually catches it make this quite a silly thing to impliment. A lot of the "new" C++ features a simply going to add more bloat, slower code and features, like the one above. That are useless. I personally would like to see more behaviour defined, like default calling conventions. Or even just things like i++ + i--;, even if that is trivial. Another thing would be vtable manipulation, the order of the vtable in derived classes (that have pure or non-pure virtual functions) should be another thing. Redirecting the vtable in some cases can be quite useful. As far as I know, the pointer to the table is not even defined. It could be at any offset to the instance pointer too.
Re: I Learn Some Basic C++! [message #392533 is a reply to message #391886] Sat, 27 June 2009 09:50 Go to previous messageGo to next message
futura83
Messages: 1285
Registered: July 2006
Location: England
Karma: 0
General (1 Star)
Viva la Resistance!
Or be lazy and disregard the BODMAS rules altogether and do the calculations you want in the order you do them.



As in, assign another variable, and do the calculation in stages.


Instead of 100 * (a + b + c)....etc, add:

double f;
f = a + b + c;
f *= 100;





That way your calculations are done in the order you write them, without having an understanding of BODMAS.


P.S. This is from an A-level maths student who has no trouble with BODMAS as well. Razz



Edit: If you really don't like brackets in your example, simply do:

100 * a + 100 * b....etc....


This is a signature. Reading this is wasting your time.

[Updated on: Sat, 27 June 2009 09:51]

Report message to a moderator

Re: I Learn Some Basic C++! [message #392551 is a reply to message #391886] Sat, 27 June 2009 11:50 Go to previous messageGo to next message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
thanks for tips guys, i know im dumb to get confussed on the order of how to do the muliplication, but you say do the order, so i guesss that means the first number i want anythign done wioth i should put into brackets then lets say * 100? but does it matter which direction u right the code? like

<< (a + b + c) *100

or

<< 100 * (a + B + c)


and lets pretned the answer is 2000 which one will come out with the right one? is
Re: I Learn Some Basic C++! [message #392562 is a reply to message #392551] Sat, 27 June 2009 12:05 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
SSnipe wrote on Sat, 27 June 2009 20:50

thanks for tips guys, i know im dumb to get confussed on the order of how to do the muliplication, but you say do the order, so i guesss that means the first number i want anythign done wioth i should put into brackets then lets say * 100? but does it matter which direction u right the code? like

<< (a + b + c) *100

or

<< 100 * (a + B + c)


and lets pretned the answer is 2000 which one will come out with the right one? is

they both do unless the capital B in the second example is another variable Razz
Guess that was supposed to be a 'b' also Smile


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg
Re: I Learn Some Basic C++! [message #392570 is a reply to message #392562] Sat, 27 June 2009 12:55 Go to previous messageGo to next message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
Omar007 wrote on Sat, 27 June 2009 12:05

SSnipe wrote on Sat, 27 June 2009 20:50

thanks for tips guys, i know im dumb to get confussed on the order of how to do the muliplication, but you say do the order, so i guesss that means the first number i want anythign done wioth i should put into brackets then lets say * 100? but does it matter which direction u right the code? like

<< (a + b + c) *100

or

<< 100 * (a + B + c)


and lets pretned the answer is 2000 which one will come out with the right one? is

they both do unless the capital B in the second example is another variable Razz
Guess that was supposed to be a 'b' also Smile

*b Razz
Re: I Learn Some Basic C++! [message #392624 is a reply to message #391886] Sat, 27 June 2009 20:11 Go to previous messageGo to next message
Doitle is currently offline  Doitle
Messages: 1723
Registered: February 2003
Location: Chicago, IL
Karma: 0
General (1 Star)
Moderator/Captain

Good to see you are finally getting into some programming SSnipe.

Also SK I dont know why but even in my EE classes when doing C++ they have us using CIN and COUT... not printf and scanf...


http://www.n00bstories.com/image.fetch.php?id=1285726594
Re: I Learn Some Basic C++! [message #392632 is a reply to message #392624] Sat, 27 June 2009 20:57 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Doitle wrote on Sat, 27 June 2009 22:11

Also SK I dont know why but even in my EE classes when doing C++ they have us using CIN and COUT... not printf and scanf...


That makes me sad. Really.


-Jelly Administrator
-Exodus Administrator
Re: I Learn Some Basic C++! [message #393156 is a reply to message #392632] Tue, 30 June 2009 10:12 Go to previous messageGo to next message
Sir Kane
Messages: 1701
Registered: March 2003
Location: Angerville
Karma: 0
General (1 Star)
raven wrote on Sat, 27 June 2009 22:57

Doitle wrote on Sat, 27 June 2009 22:11

Also SK I dont know why but even in my EE classes when doing C++ they have us using CIN and COUT... not printf and scanf...


That makes me sad. Really.

Very sad, indeed. They possibly do that because it's "easy to use". With printf/scanf you have to remember all the format options, but once you get used to them, it's awesome.


Proud N9500 and proud N6270 user. Creator of the IEE libraries (original bhs.dll) and the RB series software.
http://n00bstories.com/image.fetch.php?id=1189992501http://www.n00bstories.com/image.fetch.php?id=1257492907
Re: I Learn Some Basic C++! [message #393191 is a reply to message #393156] Tue, 30 June 2009 12:19 Go to previous messageGo to next message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
Sir Kane wrote on Tue, 30 June 2009 10:12

raven wrote on Sat, 27 June 2009 22:57

Doitle wrote on Sat, 27 June 2009 22:11

Also SK I dont know why but even in my EE classes when doing C++ they have us using CIN and COUT... not printf and scanf...


That makes me sad. Really.

Very sad, indeed. They possibly do that because it's "easy to use". With printf/scanf you have to remember all the format options, but once you get used to them, it's awesome.

I stopped reading the book for like 4 or 5 days since i had chores and job interviews and shit and learning some Spanish, im read it again today since im free in just a little bit tbh, but i think printf and scanf is next to learn..I saw it bringing it up so im guessing its next...but

I had an idea of a very simple console program I want to try next, Iv been learning Spanish, and all the words and there English translations i written down, I want to write a small consol thing so it ask me "what does this word mean in Spanish" and if i type it incorrect it will tell me, and only ask me the words i type in the code (the only workds i know) kind alike flash cards just the lazy way but that wont be untill a while Wink
Re: I Learn Some Basic C++! [message #394203 is a reply to message #391886] Tue, 07 July 2009 01:11 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
So how's it going?


Re: I Learn Some Basic C++! [message #394204 is a reply to message #394203] Tue, 07 July 2009 01:32 Go to previous messageGo to next message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
reborn wrote on Tue, 07 July 2009 01:11

So how's it going?

I have not gotten far, honeslty summers been busy. im on like page 20 something, not far at all, but im start reading it soon, but learning Spanish, summer school, my new job, summer chores, and my girl & the gym, have been keeping my busy, i have not done c++ nor Spanish in over a week....so once i get my new job schedule, im find a way to fit it all in since as of this whole week my whole week was unpredictable
Re: I Learn Some Basic C++! [message #396851 is a reply to message #391886] Sun, 02 August 2009 14:26 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
So how's it going?

By even Chapter five you should be able to start seeing how you could incorperate this stuff into renegade. Smile



Re: I Learn Some Basic C++! [message #396852 is a reply to message #396851] Sun, 02 August 2009 14:35 Go to previous message
_SSnipe_ is currently offline  _SSnipe_
Messages: 4121
Registered: May 2007
Location: Riverside Southern Califo...
Karma: 0
General (4 Stars)
reborn wrote on Sun, 02 August 2009 14:26

So how's it going?

By even Chapter five you should be able to start seeing how you could incorperate this stuff into renegade. Smile

I have not gotten any furture since my last post, iv been flooded...working 9 hours a day. plus 2 for transportation, summer school, chores, church, cleaning, and ya, but once summer school ends im start reading where i left off at (it ends in 1 more week!)
Previous Topic: Your daily commute to work!
Next Topic: Virus
Goto Forum:
  


Current Time: Mon Nov 25 02:04:55 MST 2024

Total time taken to generate the page: 0.01218 seconds