• We've upgraded our forums. Please post any issues/requests in this thread.

C++ small tutorial

Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#1
I was reading a book and went through a problem of mine.
In November i tried to make a formula in math, but the number was way too huge and
i couldn't hope anymore in my skills in math. I just found the square power of it,
but not the cube. So now i remember it all, and i was thinking...
What about this one: 2^2^2 ?
And made it even more interesting finding a new programming method like this:
pow(2, pow(2, 2));
from this:
pow(2, 2);
This means that you can call same function inside the function!
Well i didn't use it and didn't think of it till now...
So let's hope someone else will find a use of it and here is all the program:
Code:
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    cout << pow(2, pow(2, 2));
    cin.get();
}
 

brandonwh64

Addicted to Bacon and StarCrunches!!!
Joined
Sep 6, 2009
Messages
19,516 (6.46/day)
Likes
6,937
Location
Chatsworth, GA
System Name The StarCrunch Defender! | X58 Cruncher!
Processor I7 6700K @ STOCK | Intel I7-920
Motherboard Gigabyte Z170X-UD5 | Alienware MS-7543 X58
Cooling Corsair A70 Push/Pull | Corsair H50
Memory Crucial Ballistix DDR4 2400 MHz | Pereema 3x2GB DDR3
Video Card(s) Gigabyte Gaming G1 GTX 1070 | Gigabyte 7970 3GB
Storage 2x Samsung Pro 256GB M.2 SSD's in Raid 0 | 4TB Western Digital SATA drive
Display(s) ViewSonic VG2227wm 1080P | OLD viewsonics
Case NZXT Tempest 410 Elite | NZXT Source 210
Audio Device(s) Onboard
Power Supply Corsair 750TX | Enermax Liberty 500W
Mouse MX518 | MX502
Keyboard TESORO Mechanical | ANZO Mechanical
Software Windows 10 Pro on both
#2
ALEK you are going to be my hero! I am currently in a C++ class and I am struggling bad :( Hope if you dont mind, I could ask you some questions soon?


*EDIT*

I tried to use your code and got an error, it would not compile

 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#3
Actually you are using the microsoft VC++ which is a different compiler from the gcc
In order to compile my program, you need to download codeblocks as an ide with its mingw
compiler:
http://sourceforge.net/projects/cod...10.05/Windows/codeblocks-10.05mingw-setup.exe

If you want to go advanced you can download only the mingw compiler and write the program on a notepad and save it as program.cpp, than open cmd, find the file path and than type in gcc program.cpp.
Here is the MinGW:
http://sourceforge.net/projects/mingw/files/MinGW/

Another way is to link the libraries with your visual studio, but that would take more thinking time to link cuz there are 2 libraries.
(and i don't know if this one works)

Last, but not least:
http://msdn.microsoft.com/en-us/library/dt5dakze(v=vs.71).aspx

This is for your compiler and i don't know the VC++, i cannot help you there!

EDIT: I remember reading from the book that instead of:
#include <iostream>
#include <cmath>

Some old compilers have it:
#include <iostream.h>
#include <math.h>

Maybe it is worth a try
 
Last edited:

brandonwh64

Addicted to Bacon and StarCrunches!!!
Joined
Sep 6, 2009
Messages
19,516 (6.46/day)
Likes
6,937
Location
Chatsworth, GA
System Name The StarCrunch Defender! | X58 Cruncher!
Processor I7 6700K @ STOCK | Intel I7-920
Motherboard Gigabyte Z170X-UD5 | Alienware MS-7543 X58
Cooling Corsair A70 Push/Pull | Corsair H50
Memory Crucial Ballistix DDR4 2400 MHz | Pereema 3x2GB DDR3
Video Card(s) Gigabyte Gaming G1 GTX 1070 | Gigabyte 7970 3GB
Storage 2x Samsung Pro 256GB M.2 SSD's in Raid 0 | 4TB Western Digital SATA drive
Display(s) ViewSonic VG2227wm 1080P | OLD viewsonics
Case NZXT Tempest 410 Elite | NZXT Source 210
Audio Device(s) Onboard
Power Supply Corsair 750TX | Enermax Liberty 500W
Mouse MX518 | MX502
Keyboard TESORO Mechanical | ANZO Mechanical
Software Windows 10 Pro on both
#4
Ahhh ok, We have to use this in class :(
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#5
In VC++ the math function POW is overloaded to accept a double, float and long double.
By giving the POW function two integers the compiler cannot figure out what you want it to use.

Try this ...
Code:
cout << Pow((double)2, Pow((double)2, 2));
Given the overloads a standard ANSI C++ compiler must give this error. VC++ has attempted to adhere to ANSI standard C++ compiler as much as possible.

As a side note, you are not calling a function within a function. You are telling the compiler to call the Pow function and use it as input to another function (in this case also Pow). This is very common in programming.

You are really doing this ...
Code:
int a = Pow((double)2, 2);
cout << Pow((double)2, a);
The difference with placing the function inline as an input paramter is that the compiler is creating an unnamed variable at runtime instead of you explicitely creating one at design time.
 

brandonwh64

Addicted to Bacon and StarCrunches!!!
Joined
Sep 6, 2009
Messages
19,516 (6.46/day)
Likes
6,937
Location
Chatsworth, GA
System Name The StarCrunch Defender! | X58 Cruncher!
Processor I7 6700K @ STOCK | Intel I7-920
Motherboard Gigabyte Z170X-UD5 | Alienware MS-7543 X58
Cooling Corsair A70 Push/Pull | Corsair H50
Memory Crucial Ballistix DDR4 2400 MHz | Pereema 3x2GB DDR3
Video Card(s) Gigabyte Gaming G1 GTX 1070 | Gigabyte 7970 3GB
Storage 2x Samsung Pro 256GB M.2 SSD's in Raid 0 | 4TB Western Digital SATA drive
Display(s) ViewSonic VG2227wm 1080P | OLD viewsonics
Case NZXT Tempest 410 Elite | NZXT Source 210
Audio Device(s) Onboard
Power Supply Corsair 750TX | Enermax Liberty 500W
Mouse MX518 | MX502
Keyboard TESORO Mechanical | ANZO Mechanical
Software Windows 10 Pro on both
#6
Nope I just copied and pasted his that he made. Im a novice with only 1 week of hands on C++

I just need the basics explained to me instead of what my teacher did and give me 2 chapters to read that I couldn't understand a damn thing LOL
 
Joined
Nov 4, 2005
Messages
9,950 (2.25/day)
Likes
2,309
System Name MoFo 2
Processor AMD PhenomII 1100T @ 4.2Ghz
Motherboard Asus Crosshair IV
Cooling Swiftec 655 pump, Apogee GT,, MCR360mm Rad, 1/2 loop.
Memory 8GB DDR3-2133 @ 1900 8.9.9.24 1T
Video Card(s) HD7970 1250/1750
Storage Agility 3 SSD 6TB RAID 0 on RAID Card
Display(s) 46" 1080P Toshiba LCD
Case Rosewill R6A34-BK modded (thanks to MKmods)
Audio Device(s) ATI HDMI
Power Supply 750W PC Power & Cooling modded (thanks to MKmods)
Software A lot.
Benchmark Scores Its fast. Enough.
#7
by creating a unnamed parameter you may also find that the contents read from whatever junk leftover in that block of system ram will create issues.
 

brandonwh64

Addicted to Bacon and StarCrunches!!!
Joined
Sep 6, 2009
Messages
19,516 (6.46/day)
Likes
6,937
Location
Chatsworth, GA
System Name The StarCrunch Defender! | X58 Cruncher!
Processor I7 6700K @ STOCK | Intel I7-920
Motherboard Gigabyte Z170X-UD5 | Alienware MS-7543 X58
Cooling Corsair A70 Push/Pull | Corsair H50
Memory Crucial Ballistix DDR4 2400 MHz | Pereema 3x2GB DDR3
Video Card(s) Gigabyte Gaming G1 GTX 1070 | Gigabyte 7970 3GB
Storage 2x Samsung Pro 256GB M.2 SSD's in Raid 0 | 4TB Western Digital SATA drive
Display(s) ViewSonic VG2227wm 1080P | OLD viewsonics
Case NZXT Tempest 410 Elite | NZXT Source 210
Audio Device(s) Onboard
Power Supply Corsair 750TX | Enermax Liberty 500W
Mouse MX518 | MX502
Keyboard TESORO Mechanical | ANZO Mechanical
Software Windows 10 Pro on both
#8
I still get errors when I use your code kreji
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#9
Feel free to start your own thread with C++ questions Brandon.

Okay, I didn't test in in the compiler and just spewed from memory. :D
Back in a few minutes.
 

brandonwh64

Addicted to Bacon and StarCrunches!!!
Joined
Sep 6, 2009
Messages
19,516 (6.46/day)
Likes
6,937
Location
Chatsworth, GA
System Name The StarCrunch Defender! | X58 Cruncher!
Processor I7 6700K @ STOCK | Intel I7-920
Motherboard Gigabyte Z170X-UD5 | Alienware MS-7543 X58
Cooling Corsair A70 Push/Pull | Corsair H50
Memory Crucial Ballistix DDR4 2400 MHz | Pereema 3x2GB DDR3
Video Card(s) Gigabyte Gaming G1 GTX 1070 | Gigabyte 7970 3GB
Storage 2x Samsung Pro 256GB M.2 SSD's in Raid 0 | 4TB Western Digital SATA drive
Display(s) ViewSonic VG2227wm 1080P | OLD viewsonics
Case NZXT Tempest 410 Elite | NZXT Source 210
Audio Device(s) Onboard
Power Supply Corsair 750TX | Enermax Liberty 500W
Mouse MX518 | MX502
Keyboard TESORO Mechanical | ANZO Mechanical
Software Windows 10 Pro on both
#10
Feel free to start your own thread with C++ questions Brandon.

Okay, I didn't test in in the compiler and just spewed from memory. :D
Back in a few minutes.
Oh, I thought this was a C++ Tutorial thread? Im sorry kreji :( Just trying to get a better understanding of this stuff and by watching the masters (You guys here at TPU) I may catch on.
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#11
Sorry Brandon, I did not mean to imply you could not ask question here, just that you could start your own thread if you want. :toast:

VC++ is fussing still. Have to get back to you on that as I''m out of time tonight. :(


Got it ... here you go ...
Code:
#include "stdafx.h"
#include "iostream"
#include "cmath"

using namespace System;

int main(array<System::String ^> ^args)
{
    using namespace std;
    cout << pow((double)2, pow((double)2, 2));
    return 0;
}
Sorry, I'm a little rusty at C++. DOH !!
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#12
If you make it at school, than the best tutorial is the book in school
The teacher wont give anything outside the book
We made C++ and Java without a book and it was extremely difficult to understand
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#13
When I first learned C++ years ago, I found the hardest part to be the transition from working in a functional programming language (C, Pascal, etc.) to an object oriented language. After writing code for years with a functional mindset, the abstract concepts of OOP were quite foriegn and almost seems superfluous at the time. Of course, once I really understood OOP, there was no looking back as it's advantages and benefits became readily apparant.

Learning the new syntax of different language is really the easy part, as once you get some code working you basically won't forget how to use the syntax for any given example, or at least know where to find it in a programming reference.

IMHO, the best thing anyone could possible do is to find themselves a mentor who is willing to answer all the questions that you will have on the undelying concepts of a given programming paradigm, and hopefully one who has a great deal of patience and the ability to present things from different angles when something is just not sinking in. Thankfully, I was blessed with a mentor who besides being a coding god, had both of those traits, and to this day is a very good friend. He has since moved into higher management levels at GE and I now code more than he does, but I still pick his brain on the rare occasion when I have questions on really low level code.

When I was learning to code, the internet as we know it did not exist, so the new coders have a great advantage as there are many fine coders here on TPU who are willing to share their knowledge and experience simply for the asking, and who remember what it was like to be a coding n00b with more questions than answers. :D
 
Joined
Jun 2, 2011
Messages
739 (0.31/day)
Likes
125
System Name An experiment in continuous upgrading
Processor Intel Core i7 2600k @ 4.2 Ghz | Phenom II X4 965 | Phenom II X4 965
Motherboard MSI P67A-GD53 | MSI 990FXA-GD80 | Asus M4A79 Deluxe
Cooling Noctua NH-D14 | Zalman CNPS10x | Coolermaster*212+
Memory Kingston KHX1866C9D3K2 |*8Gb | 8Gb
Video Card(s) MSI GTX 580 TF2 x 2 (SLI) | Sapphire Radeon 7970 + GTX 460 | Radeon 4870 1Gb
Storage Crucial M4 120gb Sata3 SSD + WD Caviar black 1Tb + 1.5Tb | WD Caviar Black 1Tb x 3 | WD Blue 500gb
Display(s) Samsung S23A700D 120hz + nVidia 3D Vision + 17" Acer secondary LCD | 40" Sony 1080p TV | Sam. 2233rz
Case Antec 1200 | Lian-Li PC-8 | Antec 302
Audio Device(s) Auzentech Prelude X-Fi + Senn. PC360 G4ME | Prelude X-Fi + Home theater | Creative HS-1200
Power Supply Corsair TX850W | Corsair TX 750 | OCZ 700
Software About 400 top-rated games. | 150 top-rated games | No games
Benchmark Scores No time for benching, I prefer gaming.
#14
When I first learned C++ years ago, I found the hardest part to be the transition from working in a functional programming language (C, Pascal, etc.) to an object oriented language. After writing code for years with a functional mindset, the abstract concepts of OOP were quite foriegn and almost seems superfluous at the time. Of course, once I really understood OOP, there was no looking back as it's advantages and benefits became readily apparant.

Learning the new syntax of different language is really the easy part, as once you get some code working you basically won't forget how to use the syntax for any given example, or at least know where to find it in a programming reference.

IMHO, the best thing anyone could possible do is to find themselves a mentor who is willing to answer all the questions that you will have on the undelying concepts of a given programming paradigm, and hopefully one who has a great deal of patience and the ability to present things from different angles when something is just not sinking in. Thankfully, I was blessed with a mentor who besides being a coding god, had both of those traits, and to this day is a very good friend. He has since moved into higher management levels at GE and I now code more than he does, but I still pick his brain on the rare occasion when I have questions on really low level code.

When I was learning to code, the internet as we know it did not exist, so the new coders have a great advantage as there are many fine coders here on TPU who are willing to share their knowledge and experience simply for the asking, and who remember what it was like to be a coding n00b with more questions than answers. :D
As a self-taught C programmer of decent skill back in the DOS days, teaching myself C++ failed miserably.

Also, what is "cout"?
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#15
It's the command to send output to the console.
 
Joined
Jun 2, 2011
Messages
739 (0.31/day)
Likes
125
System Name An experiment in continuous upgrading
Processor Intel Core i7 2600k @ 4.2 Ghz | Phenom II X4 965 | Phenom II X4 965
Motherboard MSI P67A-GD53 | MSI 990FXA-GD80 | Asus M4A79 Deluxe
Cooling Noctua NH-D14 | Zalman CNPS10x | Coolermaster*212+
Memory Kingston KHX1866C9D3K2 |*8Gb | 8Gb
Video Card(s) MSI GTX 580 TF2 x 2 (SLI) | Sapphire Radeon 7970 + GTX 460 | Radeon 4870 1Gb
Storage Crucial M4 120gb Sata3 SSD + WD Caviar black 1Tb + 1.5Tb | WD Caviar Black 1Tb x 3 | WD Blue 500gb
Display(s) Samsung S23A700D 120hz + nVidia 3D Vision + 17" Acer secondary LCD | 40" Sony 1080p TV | Sam. 2233rz
Case Antec 1200 | Lian-Li PC-8 | Antec 302
Audio Device(s) Auzentech Prelude X-Fi + Senn. PC360 G4ME | Prelude X-Fi + Home theater | Creative HS-1200
Power Supply Corsair TX850W | Corsair TX 750 | OCZ 700
Software About 400 top-rated games. | 150 top-rated games | No games
Benchmark Scores No time for benching, I prefer gaming.
#16
It's the command to send output to the console.
Damn where are the days when things were at least a little bit self-explanatory LOL. :eek:
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#17
When I first learned C++ years ago, I found the hardest part to be the transition from working in a functional programming language (C, Pascal, etc.) to an object oriented language. After writing code for years with a functional mindset, the abstract concepts of OOP were quite foriegn and almost seems superfluous at the time. Of course, once I really understood OOP, there was no looking back as it's advantages and benefits became readily apparant.

Learning the new syntax of different language is really the easy part, as once you get some code working you basically won't forget how to use the syntax for any given example, or at least know where to find it in a programming reference.

IMHO, the best thing anyone could possible do is to find themselves a mentor who is willing to answer all the questions that you will have on the undelying concepts of a given programming paradigm, and hopefully one who has a great deal of patience and the ability to present things from different angles when something is just not sinking in. Thankfully, I was blessed with a mentor who besides being a coding god, had both of those traits, and to this day is a very good friend. He has since moved into higher management levels at GE and I now code more than he does, but I still pick his brain on the rare occasion when I have questions on really low level code.

When I was learning to code, the internet as we know it did not exist, so the new coders have a great advantage as there are many fine coders here on TPU who are willing to share their knowledge and experience simply for the asking, and who remember what it was like to be a coding n00b with more questions than answers. :D
Your post is really motivating and i hoped to have your chances too in C++.
Unfortunately my mentor rejected me of being part of a project with Ogre3D for 9 months and accepted a girl who doesn't know how many bytes takes an int. That made me "VERY ANGRY" :mad: and i made the project using XNA in a single day. Now i know he was not a
mentor. He was a fool trying to tell us that call of duty black ops uses the best vertex shaders ever made. I didn't lose my patience with him and went on programming myself.
What is worse i have a lot of people arguing very bad about me and they don't want me to
study programming, but i didn't hear anything and went on reading a 1200 pages book.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#18
When making a DnD dice roller a couple of months ago I remember using several math.min functions inside each other to work out 4d6 minus the lowest roll.
 

ctrain

New Member
Joined
Jan 12, 2010
Messages
393 (0.14/day)
Likes
72
#19
I was reading a book and went through a problem of mine.
In November i tried to make a formula in math, but the number was way too huge and
i couldn't hope anymore in my skills in math. I just found the square power of it,
but not the cube. So now i remember it all, and i was thinking...
What about this one: 2^2^2 ?
And made it even more interesting finding a new programming method like this:
pow(2, pow(2, 2));
from this:
pow(2, 2);
This means that you can call same function inside the function!
Well i didn't use it and didn't think of it till now...
So let's hope someone else will find a use of it and here is all the program:
Code:
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    cout << pow(2, pow(2, 2));
    cin.get();
}
it doesn't have to be the same function.

the return is used for the argument.

Code:
#include "stdafx.h"
#include "iostream"
#include "cmath"

using namespace System;

int main(array<System::String ^> ^args)
{
    using namespace std;
    cout << pow((double)2, pow((double)2, 2));
    return 0;
}
Sorry, I'm a little rusty at C++. DOH !!
this is C++/CLI (.NET), not native C++
 
Last edited:

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#20
I know, ctrain ... that is because Brandon said he had to use VC++ in his uni classes.
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#21
*EDIT*

I tried to use your code and got an error, it would not compile
Just found your problem.
I tried it on visual studio 2010 it didn't work
It will work if you add a
file -> new project -> visual C++ -> win32 -> win32 console application -> empty project
Copy paste it and it will work. It worked on my pc
If you have trouble just post your problem or watch the steps again
:toast:
 

brandonwh64

Addicted to Bacon and StarCrunches!!!
Joined
Sep 6, 2009
Messages
19,516 (6.46/day)
Likes
6,937
Location
Chatsworth, GA
System Name The StarCrunch Defender! | X58 Cruncher!
Processor I7 6700K @ STOCK | Intel I7-920
Motherboard Gigabyte Z170X-UD5 | Alienware MS-7543 X58
Cooling Corsair A70 Push/Pull | Corsair H50
Memory Crucial Ballistix DDR4 2400 MHz | Pereema 3x2GB DDR3
Video Card(s) Gigabyte Gaming G1 GTX 1070 | Gigabyte 7970 3GB
Storage 2x Samsung Pro 256GB M.2 SSD's in Raid 0 | 4TB Western Digital SATA drive
Display(s) ViewSonic VG2227wm 1080P | OLD viewsonics
Case NZXT Tempest 410 Elite | NZXT Source 210
Audio Device(s) Onboard
Power Supply Corsair 750TX | Enermax Liberty 500W
Mouse MX518 | MX502
Keyboard TESORO Mechanical | ANZO Mechanical
Software Windows 10 Pro on both
#22
Just found your problem.
I tried it on visual studio 2010 it didn't work
It will work if you add a
file -> new project -> visual C++ -> win32 -> win32 console application -> empty project
Copy paste it and it will work. It worked on my pc
If you have trouble just post your problem or watch the steps again
:toast:
This is what I first tried and it errored when I compiled it
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#23
I know this thread is old, but to help out:
I fixed the error in Visual Studio 2010 using math.h header instead of cmath.
You should also remove the precompiled headers when starting a new empty project.
In Visual Studio 2012, it works perfect since it has the new headers and C++11.