• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 01:39
CET 07:39
KST 15:39
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners9Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win TL.net Map Contest #21: Winners RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8) StarCraft, SC2, HotS, WC3, Returning to Blizzcon!
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Path of Exile Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1538 users

The Big Programming Thread - Page 582

Forum Index > General Forum
Post a Reply
Prev 1 580 581 582 583 584 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Incognoto
Profile Blog Joined May 2010
France10239 Posts
February 08 2015 12:53 GMT
#11621
On February 08 2015 21:29 Cynry wrote:
Your main function returns an int, so you got to return an int to end it. What you return (so long as it is an int) and what it means is up to you, although I guess there are some convention. For me, -1 is an error occured, 0 nothing was done, 1 is all good.

Don't your compiler tells you about using if (x1 = x2) ? Fairly sure mine does (gcc with flags -Werror etc to show all errors).
if ((x1 = x2)) would work, not with a single pair of parenthesis.


if((x1=x2)) didn't work either, I really need "==", I don't know why.

@Blisse, I'm doing this entirely for fun. I'm just messing around with programming to understand the concepts, maybe write a few programs for fun. Industrial engineering has nothing to do with coding at all, just wanted to answer ropid. Would you recommend learning C over C++ at first, or should I just stick to messing around with C++ right now? I think I'll just stick to C++ until I understand enough about coding to figure out why C might be interesting.

From the little I understand (because a lot of what I've been reading is gibberish to me :p), it seems that C++ is more or less a lot like C, it's just that some of the extra steps that you'd have to do in C (e.g. allocating variables to memory) are done for you in C++. I've already found out that an un-initialized variable in C++ can lead to explosive results.

So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console?
maru lover forever
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
February 08 2015 12:58 GMT
#11622
On February 08 2015 21:03 Incognoto wrote:
The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine).

The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions.

Now I'm coding in C# and I'm perfectly fine because I just plain don't need to know how everything translates into machine code. The only thing I miss from time to time is templates, because generics just are nowhere near as powerful as templates, so you have to use reflection here and there instead. So what I am missing is more powerful means of abstraction, not closeness to machine code.

The idea that you need to know how programs work at machine level to be a great programmer is just nonsense. Assembly isn't the lowest you can go, machine code isn't the lowest either. You could try to learn the microcode that is run on your CPU, you could learn how that translates into signals and what not. None of that will make you a better programmer by itself. What you really need to understand is how abstractions work in programming. But ultimately you always rely on some abstractions to do what they promise to do.

I personally don't recommend C++ to start with, as it's a language with many pitfalls for the newbie, and I know from experience that there is plenty of awful resources out there on the internet that will teach you just the worst ways of using C++. But in general one language is as good of a starting point as another as long as you learn it properly.
If you have a good reason to disagree with the above, please tell me. Thank you.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-02-08 13:21:36
February 08 2015 13:20 GMT
#11623
On February 08 2015 21:53 Incognoto wrote:
Show nested quote +
On February 08 2015 21:29 Cynry wrote:
Your main function returns an int, so you got to return an int to end it. What you return (so long as it is an int) and what it means is up to you, although I guess there are some convention. For me, -1 is an error occured, 0 nothing was done, 1 is all good.

Don't your compiler tells you about using if (x1 = x2) ? Fairly sure mine does (gcc with flags -Werror etc to show all errors).
if ((x1 = x2)) would work, not with a single pair of parenthesis.


if((x1=x2)) didn't work either, I really need "==", I don't know why.

@Blisse, I'm doing this entirely for fun. I'm just messing around with programming to understand the concepts, maybe write a few programs for fun. Industrial engineering has nothing to do with coding at all, just wanted to answer ropid. Would you recommend learning C over C++ at first, or should I just stick to messing around with C++ right now? I think I'll just stick to C++ until I understand enough about coding to figure out why C might be interesting.

From the little I understand (because a lot of what I've been reading is gibberish to me :p), it seems that C++ is more or less a lot like C, it's just that some of the extra steps that you'd have to do in C (e.g. allocating variables to memory) are done for you in C++. I've already found out that an un-initialized variable in C++ can lead to explosive results.

So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console?


= parses into assignment, meaning x1=x2 means set x1 to the value of x2 (i'm skipping the details). in C/C++, everything returns a value whether you like it or not, x1=x2 returns x1, which isn't 0, which is cast to true, so the if statement is entered.
== parses into equality, meaning x1==x2 returns a boolean true/false, is the value of x1 equal to x2, which is what you want.

for fun i would totally prefer a higher level language (like visual c# or java) because c/c++ doesn't allow you to do really fun stuff unless you want to learn a whole bunch of extensions and processes which take away from the "fun" of coding. but c/c++ are definitely where you should start if you want to learn.

yes, you can check in the console whether it returned error. try returning 1 and seeing what you get as a result. i believe it should say "returned with status code...." or something like that but i might be mixing up things.
There is no one like you in the universe.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
February 08 2015 13:25 GMT
#11624
On February 08 2015 21:58 spinesheath wrote:
Show nested quote +
On February 08 2015 21:03 Incognoto wrote:
The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine).

The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions.

I think the reason why C in my opinion is a "no bullshit" langauge is because of 2 things.

1. It shows you all the pitfalls you should realisticly expect when abstractation fails.

2.It shows you how to the same shit on a lower level, which is more time consuming but more mutatable at the same time.
The harder it becomes, the more you should focus on the basics.
Dumbledore
Profile Joined April 2011
Sweden725 Posts
February 08 2015 13:40 GMT
#11625
On February 08 2015 20:59 Cynry wrote:
Show nested quote +
On February 08 2015 20:27 Dumbledore wrote:
In OP there is a quote comparing programming languages depending on how close they are to the machine.
It says:
"
Machine Lang
Assembly
C
C++/Java/C#
..."
This is utterly missleading and incorrect. C++ is a superset of C, it is compiled directly to native code (unless you do some gross CLR, which you can in C aswell). It is no further from the machine than C is. You can use every single C feature in it. C# and Java are highly abstract languages. They dont compile to native code. The applications run in what is called a "virtual machine" (no not the vmware kind), actively translating instructions and such. You lose a lot of capabilities using those languages such as being able to communicate directly to hardware. Comparing C++ to those 2 is missleading, wrong and insulting to any serious C++ programmer. The list should say "C/C++". Please fix OP.


Uneducated question :
As much as I agree with how you part C++ from Java and C#, are C and C++ really on the same "level" ? I was under the impression that one could write a C++ program without knowing what's going on with memory for exemple, whereas you can't really do that in C (I think). So it'd still be a level of abstraction higher. Wrong ?

Show nested quote +

one million years dungeon!

Whaaat ? :D


Level in this context means the relation to the machine, and C and C++ has the same. Which is why I felt annoyed that this thread is tricking people that C is closer to it. (A few posts up a guy is saying he will drop C++ for C cos its "closer").

In C++ memory management is just as crucial as in C. In C++11 Smart pointers were introduced, aka unique_ptr and shared_ptr, these allow for some kind of "automatic" memory management and should "always" be used. This will help your application use RAII (Resource Acqusition Is Initialisation). There are some differences between how you should manage memory in C and C++. In C for allocating and deallocating you should use malloc and free allover the place. In C++ malloc is now considered bad practise. You want to use "new", "delete" and smart pointers.

C++ offers smart pointers as a bonus, its not forced use. But yeah the level of c c++ is the same
Have a nice day ;)
Ropid
Profile Joined March 2009
Germany3557 Posts
February 08 2015 14:22 GMT
#11626
@incognoto:

What you can do right now is look at the debugger that's built into Visual Studio (if everything's there in the free version). You can make it go line by line through your tiny test program. You can look at what's happening to all variables. There's a "stack" where that stuff is saved on. Try creating a new function out of your "finding the determinant" line and you might intuitively understand how that works with the stack, variables and return values. You can take a look at the assembler code that your functions translated into. That might be interesting. You can probably guess what's going on if it's about integers (I don't know how floating point code looks like in assembler and I worry you shouldn't look at that, should instead do stuff with integers).

If you google "kernighan ritchie the c programming language", you'll find a pdf of the book from the C inventors. The way it's written, it doesn't talk about anything irrelevant really, just describes everything. For pointers and how dynamic memory allocation works, there's good explanations with sketches and stuff (but I don't think it has the same for the local stuff on the stack).

When you write "a = b" in something like C, that translates into "read something from memory address b and then store that into memory address a". That's why "==" is something different. When you write "a == b", that translates into "read something from memory address a and then compare that to what's at memory address b".

All of this is "imperative". There are programming languages that work differently. There are languages where when you write "a = b", you just declare to the compiler that wherever you use b, it's the same as a. The line itself does not translate into any instructions for the machine. It instead changes how the compiler will see the rest of your program.

There's a webpage "Project Euler" here: https://projecteuler.net/problems. It's a collection of simple questions where you're supposed to calculate something. You could do some of those in C. When you do that, you're thinking in a pretty different way than what you do in those other languages and those will feel weird.

Two of those weird languages that are actually in use were developed in France. There's OCaml and there's Coq. OCaml seems somewhat normal and Coq seems to be something about logic and proofs. There might be research groups in your faculty and courses that use one of those two?
"My goal is to replace my soul with coffee and become immortal."
nunez
Profile Blog Joined February 2011
Norway4003 Posts
February 08 2015 14:40 GMT
#11627
On February 08 2015 21:58 spinesheath wrote:
Show nested quote +
On February 08 2015 21:03 Incognoto wrote:
The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine).

The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions.

Now I'm coding in C# and I'm perfectly fine because I just plain don't need to know how everything translates into machine code. The only thing I miss from time to time is templates, because generics just are nowhere near as powerful as templates, so you have to use reflection here and there instead. So what I am missing is more powerful means of abstraction, not closeness to machine code.

The idea that you need to know how programs work at machine level to be a great programmer is just nonsense. Assembly isn't the lowest you can go, machine code isn't the lowest either. You could try to learn the microcode that is run on your CPU, you could learn how that translates into signals and what not. None of that will make you a better programmer by itself. What you really need to understand is how abstractions work in programming. But ultimately you always rely on some abstractions to do what they promise to do.

I personally don't recommend C++ to start with, as it's a language with many pitfalls for the newbie, and I know from experience that there is plenty of awful resources out there on the internet that will teach you just the worst ways of using C++. But in general one language is as good of a starting point as another as long as you learn it properly.

+(++*(std::make_unique<int>(0)));
conspired against by a confederacy of dunces.
Rollin
Profile Joined March 2011
Australia1552 Posts
Last Edited: 2015-02-08 14:51:26
February 08 2015 14:49 GMT
#11628
On February 08 2015 21:32 Blisse wrote:
C++ can do everything C can.


Variable length arrays exist in c99 but not c++.
Throw off those chains of reason, and your prison disappears. | Check your posting frequency timeline: http://www.teamliquid.net/mytlnet/post_activity_img.php
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
February 08 2015 15:25 GMT
#11629
On February 08 2015 22:20 Blisse wrote:
Show nested quote +
On February 08 2015 21:53 Incognoto wrote:
So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console?


yes, you can check in the console whether it returned error. try returning 1 and seeing what you get as a result. i believe it should say "returned with status code...." or something like that but i might be mixing up things.


Actually if the C function returns 0 it means success, anything else means that something went wrong. You can use this to handle errors.


if (!input) {
return 1; // no input specified
}

if (fopen("myfile", "r") == NULL) {
return 2; // could not read file, for more details see strerror(errno) if <errno.h> is included
}

return 0; // all is well
Time is precious. Waste it wisely.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
February 08 2015 15:40 GMT
#11630
I have this particular question in my mind: I'm building this web application which, in server side, uses nodejs to get constant stream of data from a 3rd party API and store it in my NoSQL database. I have finished developing the server side and now I'll move on with the client side. I'm wondering what I should use for the front end. I'm stuck between:

1- Front end with EmberJS and having a JSON API for database connectivity (or whatever Ember offers for that)
2- Same thing as #1, just replace EmberJS with AngularJS
3- Use Express and eliminate the need for JSON API for DB connectivity.

What are the pros and cons of each one?
"windows bash is a steaming heap of shit" tofucake
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
February 08 2015 15:44 GMT
#11631
On February 08 2015 20:27 Dumbledore wrote:
In OP there is a quote comparing programming languages depending on how close they are to the machine.
It says:
"
Machine Lang
Assembly
C
C++/Java/C#
..."
This is utterly missleading and incorrect. C++ is a superset of C, it is compiled directly to native code (unless you do some gross CLR, which you can in C aswell). It is no further from the machine than C is. You can use every single C feature in it. C# and Java are highly abstract languages. They dont compile to native code. The applications run in what is called a "virtual machine" (no not the vmware kind), actively translating instructions and such. You lose a lot of capabilities using those languages such as being able to communicate directly to hardware. Comparing C++ to those 2 is missleading, wrong and insulting to any serious C++ programmer. The list should say "C/C++". Please fix OP.

I'm not changing a quote from someone else from 3 years ago because you don't like it. It's really not insulting at all unless someone decides they want to be nitpicky. It's a very basic list meant to get a point across, not a specific and universal classification of C++.

And I'm well aware of how these languages work and I'm fairly sure donut is too.
Liquipediaasante sana squash banana
Dumbledore
Profile Joined April 2011
Sweden725 Posts
February 08 2015 16:11 GMT
#11632
On February 08 2015 23:49 Rollin wrote:
Show nested quote +
On February 08 2015 21:32 Blisse wrote:
C++ can do everything C can.


Variable length arrays exist in c99 but not c++.


You got me there. However you could always use dynamic arrays in C++ or std::vector.
VL Arrays were taken out of the C++ Standard fot good reasons though. e.g. sizeof() wont always work at compile time, New syntax needed for multi dimensional VL Arrays that are passed as arguments. And other stack problems it can possibly introduce.
Have a nice day ;)
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
Last Edited: 2015-02-08 16:38:35
February 08 2015 16:37 GMT
#11633
On February 09 2015 00:40 Djagulingu wrote:
I have this particular question in my mind: I'm building this web application which, in server side, uses nodejs to get constant stream of data from a 3rd party API and store it in my NoSQL database. I have finished developing the server side and now I'll move on with the client side. I'm wondering what I should use for the front end. I'm stuck between:

1- Front end with EmberJS and having a JSON API for database connectivity (or whatever Ember offers for that)
2- Same thing as #1, just replace EmberJS with AngularJS
3- Use Express and eliminate the need for JSON API for DB connectivity.

What are the pros and cons of each one?


You could always try some full stack framework, like MEAN. It uses NoSQL (Mongo), Express, Angular and Node so you could have it all in one neat package.
Time is precious. Waste it wisely.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
Last Edited: 2015-02-08 18:28:06
February 08 2015 18:27 GMT
#11634
On February 09 2015 01:37 Manit0u wrote:
Show nested quote +
On February 09 2015 00:40 Djagulingu wrote:
I have this particular question in my mind: I'm building this web application which, in server side, uses nodejs to get constant stream of data from a 3rd party API and store it in my NoSQL database. I have finished developing the server side and now I'll move on with the client side. I'm wondering what I should use for the front end. I'm stuck between:

1- Front end with EmberJS and having a JSON API for database connectivity (or whatever Ember offers for that)
2- Same thing as #1, just replace EmberJS with AngularJS
3- Use Express and eliminate the need for JSON API for DB connectivity.

What are the pros and cons of each one?


You could always try some full stack framework, like MEAN. It uses NoSQL (Mongo), Express, Angular and Node so you could have it all in one neat package.

I actually want to use couchbase as the nosql database because it is lotsnlots of times faster when it comes to write operations per second and that is what my server is going to do (think of it like some guy who picks up a single paper from an endless pile of papers, stamp it and put it in another pile and thus i don't want my pile to randomly crash).
"windows bash is a steaming heap of shit" tofucake
AKnopf
Profile Blog Joined March 2011
Germany259 Posts
February 08 2015 20:24 GMT
#11635
On February 08 2015 21:58 spinesheath wrote:
Show nested quote +
On February 08 2015 21:03 Incognoto wrote:
The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine).

The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions.

Now I'm coding in C# and I'm perfectly fine because I just plain don't need to know how everything translates into machine code. The only thing I miss from time to time is templates, because generics just are nowhere near as powerful as templates, so you have to use reflection here and there instead. So what I am missing is more powerful means of abstraction, not closeness to machine code.

The idea that you need to know how programs work at machine level to be a great programmer is just nonsense. Assembly isn't the lowest you can go, machine code isn't the lowest either. You could try to learn the microcode that is run on your CPU, you could learn how that translates into signals and what not. None of that will make you a better programmer by itself. What you really need to understand is how abstractions work in programming. But ultimately you always rely on some abstractions to do what they promise to do.

I personally don't recommend C++ to start with, as it's a language with many pitfalls for the newbie, and I know from experience that there is plenty of awful resources out there on the internet that will teach you just the worst ways of using C++. But in general one language is as good of a starting point as another as long as you learn it properly.

As a rubyist I can only kiss you for this comment. C is a fine language, but it's not the holy grail of programming as so many people propagate. At the end it's always a matter of what level of abstraction is best for the kind of program you want to write. Also: While it is true, that you can do lots of run-time and memory optimizations in C, it's also true that most applications don't need to be optimized - at least not in that way.
The world - its a funny place
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
February 08 2015 23:33 GMT
#11636
On February 08 2015 21:03 Incognoto wrote:
the discussion which took place on the last two pages was really interesting, thanks for that.

@Ropid, I'm doing a master's degree in industrial engineering. Coding in VBA seems to have almost no link whatsoever to the rest of what we do, so I'm not really sure what the fuck we're doing. I decided to pick up C++ for fun, completely on my own.

So far I've written just one program, in C++, using visual C++. It will solve a basic univariate quadratic function. It was fun to do, I did it reading the first few pages of learncpp.com and using google whenever I couldn't get something to work (disregard the weird comments I used while writing):

+ Show Spoiler +

#include "stdafx.h" // Uncomment this line if using Visual Studio
#include <iostream>

int main()
{
//telling the user what's up
std::cout << "Dear Sir, regarding your recent enquiry as to me, the Computer, helping you do" << std::endl;
std::cout << "your math homework, I have decided that I shall give you all the aid which you" << std::endl;
std::cout << "shall need in order to successfully solve the math problem which has "<< std::endl;
std::cout << "been bestowed upon you." << std::endl;
std::cout << "I believe that indeed, you were given a polynomial equation to solve." << std::endl;
std::cout << std::endl;

//initializing the first variables that the user will enter
float a=0;
float b=0;
float c=0;

//the user will enter the variables for each value, whilst being treated like a gentleman:
std::cout << "Let us begin. Good Sir, please enter the first coefficient: "<< std::endl;
std::cin >> a;

std::cout << "Good Sir, please enter the second coefficient: "<< std::endl;
std::cin >> b;

std::cout << "Good Sir, please enter the third coefficient: "<< std::endl;
std::cin >> c;

std::cout << std::endl;


//finding da determinant:
float d=0;
d=((pow(b,2))-4*a*c);


std::cout << d << std::endl;
//checking if determinant is negative:
if(d<0)
{
std::cout << "The determinant being negative, there is no solution." << std::endl;
}
else
{


//defining solutions and doing da maths:
float x1=0;
float x2=0;

x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);

//portraying the result, which depends on the value of determinant:
if(x1==x2)
{
std::cout << "The only solution to the equation is: " << x1 << std::endl;
}
else
{
std::cout << "The first solution to your problem would be: " << x1 << std::endl;
std::cout << "This is the second result: " << x2 << std::endl;
}

}

//ending message
std::cout << std::endl;
std::cout << "My regards have been sent. Press enter to cheerio."<< std::endl;


//preventing the retarded console from shutting down on its own
std::cin.clear();
std::cin.ignore(255, '\n');
std::cin.get();

return 0;
}



Having read the OP, I might drop C++ for now and concentrate on Assembly or C, since apparently those languages are closer to the actual machine. Learning those would make me understand programming on a more "fundamental" level. Not entirely sure.

This is mostly just a hobby I'm starting, really for fun. However it seems that coding can be dangerous if self taught. For example, in my program:

if(x1==x2)


Originally, I wrote " if(x1=x2) " and what the program would do is always give me two solutions which were equal. I find it somewhat alarming that the condition I set for an "if loop" would actually transform x2 instead. Using a bit of google, I found that a work if loop in another program just used "==" instead of "="; when I edited my line with that, it ended up working.

I find this similar to playing with fire for some reason, like learning to code this way might have me ignoring really fundamental concepts or something.

The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine).


PS: everyone uses "return 0;" but I still don't know why the hell it's there. To return 0 to the machine so it knows that the program finished? Why would we need to do that? If the program works, it works, if it doesn't, it doesn't. The machine doesn't care, it's just there to execute codes.

Or it it?


You may use this to hold console open:

system("PAUSE")
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-02-09 03:22:45
February 09 2015 03:06 GMT
#11637
On February 09 2015 00:25 Manit0u wrote:
Show nested quote +
On February 08 2015 22:20 Blisse wrote:
On February 08 2015 21:53 Incognoto wrote:
So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console?


yes, you can check in the console whether it returned error. try returning 1 and seeing what you get as a result. i believe it should say "returned with status code...." or something like that but i might be mixing up things.


Actually if the C function returns 0 it means success, anything else means that something went wrong. You can use this to handle errors.


if (!input) {
return 1; // no input specified
}

if (fopen("myfile", "r") == NULL) {
return 2; // could not read file, for more details see strerror(errno) if <errno.h> is included
}

return 0; // all is well


not sure where we were in disagreement

edit: nvm i didnt see the stuff in incognoto's parentheses
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-02-09 04:23:51
February 09 2015 04:22 GMT
#11638
java question

If I pass a reference to another instance as an argument, can I make it so that all of the methods in the new instance will recognize the fields in that reference? like for example a string in the original instance, I can print it from within the constructor of the new instance, but if I try to print it from a method that is called in that constructor, it won't work unless I pass it on as a parameter to that method as well. but that seems really redundant if I am going to be using a bunch of methods... having to put the reference as a parameter over and over. does anyone understand what I am talking about?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2015-02-09 04:41:25
February 09 2015 04:38 GMT
#11639
It sounds like you need inheritance, but I'm not 100% sure what you're asking.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 09 2015 04:50 GMT
#11640

class1{ String mystring="blah" }

class2 {
class1 x = new class1
class3 y = new class3(x)}

class3{

class3(class1 thing){
System.out.print(thing.mystring);
method();
}

method(){
System.out.print(thing.mystring);
}}


hopefully the code is good here. I made it as simple as possible.
in this example I believe that mystring would print out as "blah" the first time, but the 2nd time method will not see thing anymore. so it won't print out mystring, it would just have an error. I am wondering if there is an easy way to make method and any other methods in class3 to see thing.
Prev 1 580 581 582 583 584 1032 Next
Please log in or register to reply.
Live Events Refresh
Korean StarCraft League
03:00
Week 82
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 206
ProTech122
StarCraft: Brood War
Sea 928
Zeus 585
Noble 21
Hm[arnc] 21
Bale 13
Dota 2
NeuroSwarm94
LuMiX1
League of Legends
JimRising 634
Reynor19
Counter-Strike
fl0m320
Other Games
summit1g16780
tarik_tv13013
WinterStarcraft376
C9.Mang0373
FrodaN182
Organizations
Other Games
gamesdonequick750
Counter-Strike
PGL151
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki14
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt709
Other Games
• Shiphtur173
Upcoming Events
CranKy Ducklings
3h 21m
IPSL
11h 21m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
11h 21m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
13h 21m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
16h 21m
Sparkling Tuna Cup
1d 3h
WardiTV Korean Royale
1d 5h
IPSL
1d 11h
JDConan vs WIZARD
WolFix vs Cross
LAN Event
1d 11h
BSL 21
1d 13h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
[ Show More ]
Replay Cast
2 days
Wardi Open
2 days
WardiTV Korean Royale
3 days
Replay Cast
4 days
Kung Fu Cup
4 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
5 days
RSL Revival
5 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.