• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:49
CET 20:49
KST 04:49
  • 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
Behind the Blue - Team Liquid History Book15Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8herO wins SC2 All-Star Invitational14
Community News
LiuLi Cup: 2025 Grand Finals (Feb 10-16)8Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2Nexon's StarCraft game could be FPS, led by UMS maker7PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)12Weekly Cups (Jan 26-Feb 1): herO, Clem, ByuN, Classic win2
StarCraft 2
General
How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Behind the Blue - Team Liquid History Book Weekly Cups (Jan 12-18): herO, MaxPax, Solar win Rongyi Cup S3 - Preview & Info Nexon's StarCraft game could be FPS, led by UMS maker
Tourneys
LiuLi Cup: 2025 Grand Finals (Feb 10-16) PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April WardiTV Mondays
Strategy
Custom Maps
Map Editor closed ? [A] Starcraft Sound Mod
External Content
The PondCast: SC2 News & Results Mutation # 512 Overclocked Mutation # 511 Temple of Rebirth Mutation # 510 Safety Violation
Brood War
General
Gypsy to Korea Liquipedia.net NEEDS editors for Brood War ACS replaced by "ASL Season Open" - Starts 21/02 Recent recommended BW games [ASL21] Potential Map Candidates
Tourneys
Small VOD Thread 2.0 Escore Tournament StarCraft Season 1 [Megathread] Daily Proleagues KCM Race Survival 2026 Season 1
Strategy
Fighting Spirit mining rates Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta
Other Games
General Games
Diablo 2 thread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread ZeroSpace Megathread EVE Corporation
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
Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Ask and answer stupid questions here! Russo-Ukrainian War Thread Sex and weight loss Canadian Politics Mega-thread
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
ADHD And Gaming Addiction…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1482 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
Poland17660 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
Hyrule19192 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
Poland17660 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
Next event in 4h 11m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 711
IndyStarCraft 201
SteadfastSC 154
UpATreeSC 133
BRAT_OK 89
ForJumy 27
StarCraft: Brood War
Shuttle 904
Larva 471
Light 202
Mini 151
nyoken 112
Sharp 105
firebathero 70
Movie 44
Mong 42
Hm[arnc] 31
[ Show more ]
NaDa 9
Dota 2
Gorgc5466
NeuroSwarm102
League of Legends
C9.Mang067
Counter-Strike
pashabiceps2381
fl0m1922
Heroes of the Storm
Liquid`Hasu324
Khaldor153
Other Games
Grubby3591
Sick322
ToD148
ArmadaUGS123
Trikslyr67
Mew2King58
KnowMe25
MindelVK19
Organizations
Other Games
BasetradeTV19
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Shameless 25
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• 80smullet 23
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV418
League of Legends
• imaqtpie2219
• TFBlade1595
• Shiphtur372
Upcoming Events
Replay Cast
4h 11m
Escore
14h 11m
LiuLi Cup
15h 11m
Serral vs Zoun
Cure vs Classic
Big Brain Bouts
21h 11m
ByuN vs GgMaChine
Serral vs Jumy
RSL Revival
1d 7h
RSL Revival
1d 12h
LiuLi Cup
1d 15h
uThermal 2v2 Circuit
1d 16h
RSL Revival
1d 22h
Replay Cast
2 days
[ Show More ]
Sparkling Tuna Cup
2 days
LiuLi Cup
2 days
Replay Cast
3 days
Replay Cast
3 days
LiuLi Cup
3 days
Wardi Open
3 days
Monday Night Weeklies
3 days
OSC
4 days
WardiTV Winter Champion…
4 days
Replay Cast
5 days
WardiTV Winter Champion…
5 days
Replay Cast
6 days
The PondCast
6 days
KCM Race Survival
6 days
WardiTV Winter Champion…
6 days
Liquipedia Results

Completed

Proleague 2026-02-10
Rongyi Cup S3
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
LiuLi Cup: 2025 Grand Finals
Nations Cup 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8

Upcoming

Escore Tournament S1: W8
[S:21] ASL SEASON OPEN 1st Round
[S:21] ASL SEASON OPEN 1st Round Qualifier
[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
WardiTV Winter 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
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 © 2026 TLnet. All Rights Reserved.