Best programming language?

#1
I'm thinking about maybe learning programming, and I was wondering what the recommendation would be on which programming language is best starting out...?
I've heard Visual Basic is good for beginners, but I want to know if that is actually true. I've also heard C++ is a good overall language to learn as its syntax has been copied and imitated by countless other languages, and is one of the most widely used too...is this true?

Thanks in advance.

Jake
 

JustinW

Super Moderator
Staff member
#2
I find VB the least cryptic. I've tried to learn Java and such in the past. Even with VB under my belt though, it still took taking a 5 month class in VB to force myself to try hard enough and get to where I am.

Really my best answer for you is choose a language thats cross platform or appears to fit your needs (ie pick a ide and language for game development specifically if you want to design games, etc)
 
#3
Ok, so is VB cross-platform, i.e. can be used from either Windows or Linux?
 

JustinW

Super Moderator
Staff member
#4
There's compilers out there to compile your code for non-Windows but I can't tell you how good they are. It kinda also depends on what the application does....

If you want cross platform Javas good.
 
#5
There's compilers out there to compile your code for non-Windows but I can't tell you how good they are. It kinda also depends on what the application does....

If you want cross platform Javas good.
I take it by that statement VB isn't cross-platform? Alright, well, maybe I'll try Java instead then...
 

JustinW

Super Moderator
Staff member
#6
Yeah not out of the box. Javas great because though you need x version for x os the code of your application remains the same.
 
#7
Alright...cool. Then it sounds like Java is the language for me, as I would want to especially use it from Linux (and maybe every now and then, Windows as well).

Thanks Justin.

Addendum:

I have another question...
What do you think is the best compiler for Windows (XP and/or Vista), and the best compiler for Ubuntu Linux? Is Code::Blocks a good cross-platform choice?
 
Last edited:

JustinW

Super Moderator
Staff member
#8
I'm not familar much with stuff outside VS at the moment (its a ongoing learning proccess for myself :smile:), but whatever meets your needs/has the features you want is the one you should go with.
 
#9
Yeah, I understand. :wink: Well, I got to playing around with the afore-mentioned compiler, using the C++ programming language, and I'm having a problem with a simple program I tried to create. :tongueout: Here it is...

#include <iostream>

using namespace std;

int main()
{
int a, b, c;

a = 4 * 6; // (Note use of comments and of semicolon) a is 24
b = a + 5; // b equals the original value of a with five added to it
c == 5; // Does NOT assign five to c. Rather, it checks to see if c equals 5.

cout<<"Please enter letter a, b, or c: ";
cin>> a, b, c;
cout<<"You entered: "<< a << b << c <<"\n";
cin.get();

}
Now, as you can see, the program displays the message "Please enter letter a, b, or c:" and waits for your response. Unfortunately, though currently when I type in any of those letters, I get the output of several numbers rather than what was originally intended. :huh: For instance, instead of displaying "24" as the value of "a" when typed in, it gives off a whole bunch of numbers that obviously aren't that! :lol:

Notice I declared a, b, and c as integers using "int a, b, c" without the quotes, and then on the following section, I gave it some simple math imput (making sure to end each line with a semicolon as appropriate). But its not displaying the correct thing for some reason...:frowning: The program opens (without throwing me any kind of error messages) after I compile it, but its just not returning the correct info, is all.

Oh well...I guess I'll have to have another go at it tomorrow. Its getting pretty late over here.

Jake
 
Last edited:
#11
I notice you dont have a closing } What is it outputing to the terminal?
Sorry...that was a simple copying mistake. :wink: I missed it when I copied it, but its actually there. (I'll edit my last post now)

Addendum:

The output is "Please enter letter a, b, or c:"
So I enter a, and it gives me the following output:

You entered: 24294246758

Process returned 0 <0x0> execution time : 31.687 s
Press any key to continue.
So I press a key, and the console closes. :smile: As you can see its not giving back the value "24" when I enter "a" as I want it to.
 
Last edited:

JustinW

Super Moderator
Staff member
#12
A lot of times, you must "initalize" your variables (even when you're not ready to give them values). For example, string variables may need to be initially given an emptry string for thier values or integers a 0 for thier values until you're ready to give them the values the program well work with.

I just put it into a new VS project and it did as you described except when I entered a variable and hit enter, it threw a runtime error because variable c hasn't been initalized. I dont see why you need to check c for 5 unless you want to throw in a if code block to preform an action if thats the case, so get rid of the extra = so c gets the intial value of 5, like this:

c = 5;
 
#13
A lot of times, you must "initalize" your variables (even when you're not ready to give them values). For example, string variables may need to be initially given an emptry string for thier values or integers a 0 for thier values until you're ready to give them the values the program well work with.

I just put it into a new VS project and it did as you described except when I entered a variable and hit enter, it threw a runtime error because variable c hasn't been initalized. I dont see why you need to check c for 5 unless you want to throw in a if code block to preform an action if thats the case, so get rid of the extra = so c gets the intial value of 5, like this:

c = 5;
Well, I'm not sure if that runtime error you're getting is because of the difference between VB and C++, but the fact is the program in my case runs ok, just gives me the wrong output when I enter a variable. :wink: I will try seeing if what you suggested works in my case, i.e. giving empty strings intially for my variables and seeing if i obtain any better results, but please keep in mind i am using C++ and not VB (as I'm sure they're probably quite different). :smile:

Cheers,

Jake
 

JustinW

Super Moderator
Staff member
#14
I'm not using VB. I'm actually taking your code and debugging it. I believe this should be the correct version, after playing around with it a little:

Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]#include [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]<iostream>[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]using [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] std;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] main()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] a, b, c;[/SIZE]
[SIZE=2]a = 4 * 6; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// (Note use of comments and of semicolon) a is 24[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]b = a + 5; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// b equals the original value of a with five added to it[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]c = 5; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Does NOT assign five to c. Rather, it checks to see if c equals 5.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]cout<<[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Please enter letter a, b, or c: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]cin>> a, b, c;[/SIZE]
[SIZE=2]cout<<[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"You entered: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] <<a<<[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]<<b<<[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]<<c<<[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]cin.get();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] _tmain([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] argc, _TCHAR* argv[])[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0;[/SIZE]
[SIZE=2]}[/SIZE]
You need to append spaces between your numbers for the output (a common mistake if you're not careful). The output's actually correct, but with your code there were no spaces between the variables for the output.
 
Last edited:
#15
Sorry to sound like I was instructing. I didn't know a thing about programming until I started learning yesterday shortly after starting this thread. Read an introduction tutorial which explains the basics of C++, and gives several example programs, all of which I compiled sucessfully. But the trouble came when I found those math lines mentioned in the tutorial (though not in any example), and decided I wanted to somehow work it into one of the program examples, which dealt with input from the user (by using the function cin>> which reads the input into the variable) and was designed to return the correct number entered in if a whole number, and no decimal places. And I now understand you were not using VB to test it, but VS (I guess I failed to notice it last night when I was reading). Ok, so I tried your code, using the exact same sytanx

#include <iostream>

using namespace std;

int main()
{
int a, b, c;

a = 4 * 6; // (Note use of comments and of semicolon) a is 24
b = a + 5; // b equals the original value of a with five added to it
c == 5; // Does NOT assign five to c. Rather, it checks to see if c equals 5.

cout<<"Please enter letter a, b, or c: ";
cin>> a, b, c;
cout<<"You entered: "<< a << b << c <<"\n";
cin.get();
}

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
but received the following error messages

File Line Message

F:\Programming project\Console appplication\main.cpp In function `int main()':
F:\Programming project\Console appplication\main.cpp 11 warning: statement has no effect|
F:\Programming project\Console appplication\main.cpp 14 warning: right-hand operand of comma has no effect|
F:\Programming project\Console appplication\main.cpp 14 warning: right-hand operand of comma has no effect|
F:\Programming project\Console appplication\main.cpp 19 error: `_TCHAR' has not been declared|
F:\Programming project\Console appplication\main.cpp 20 error: ISO C++ forbids declaration of `argv' with no type|
||=== Build finished: 2 errors, 3 warnings ===|
so obviously that did not work...
To be honest, I don't understand what that last function "(int argc, _TCHAR* argv[])" added to the syntax does. :wink: Why have it return the value of 0 when it by default already does when it reaches the closing brace?

Jake
 

Attachments

Last edited:
#16
Ok...so with a little more playing around, I discovered you can't have multiple variables mentioned in the cin>> function. And there was trouble with the c==5 line, like you suggested, so I removed all mention of c altogether, and changed the whole code to:
#include <iostream>

using namespace std;

int main()
{
int a, b;

a = 4 * 6; // (Note use of comments and of semicolon) a is 24
b = a + 5; // b equals the original value of a with five added to it

cout<<"Please enter letter a or b: ";
cin>> a;
cin>> b;
cout<<"You entered: "<< a << b <<"\n";
cin.get();
}
Now I'm getting *slightly* better results. :lol: I'm now only getting in the return value 4 numbers, instead of 10 or however many it was before. :wink: So the output in the Build Log is

Checking for existence: F:\Programming project\Console appplication\bin\Debug\Console appplication.exe
Executing: "E:\Program Files\CodeBlocks/cb_console_runner.exe" "F:\Programming project\Console appplication\bin\Debug\Console appplication.exe" (in F:\Programming project\Console appplication\.)
and it compiles it. So now in the console, to start off with, it gives me the message "Please enter a or b". So I enter a and it says

You entered: 2429

Process returned 0 <0x0> execution time : 2.281 s
Press any key to continue.
I press a key, and the console closes as before. So it seems I have reduced the multiple string of numbers in the ouput to just 4. :smile: Well, at least the first 2 are correct...:|

EDIT: Hold on! I understand now what its doing. For some reason, whether I type in a or b (it doesn't matter which one), it returns the output of 2429...the 2 numbers put together! Since a=24, and b=29, for some reason it appears to be combining the two together, but why its doing that, though, I don't have any idea...
 
Last edited:

mqudsi

Mostly Harmless
Staff member
#17
There is no "best" language for anything, but C++ is probably the best stepping stone because if you truly "get" it you can can code anything else.

It all depends on where you want to go from here. If you have hopes of becoming a developer, you should start with C++ (there's a good argument for starting with Java too, but I feel C++ is the better option). If you're just looking to be able to write a program to do xxxx when you need, then using a language like Python (for Linux) or Visual Basic (for Windows) is the way to go.

----------

As for your code:
cout << a << b

Means print a then b.

You would need to use logic statements (the "if" keyword) to do either
cout << a
or
cout << b

Not cout << a << b which will print both.

And though you ask the user to enter /either/ a or b, you're requiring him to enter both.
 
#18
There is no "best" language for anything, but C++ is probably the best stepping stone because if you truly "get" it you can can code anything else.

It all depends on where you want to go from here. If you have hopes of becoming a developer, you should start with C++ (there's a good argument for starting with Java too, but I feel C++ is the better option). If you're just looking to be able to write a program to do xxxx when you need, then using a language like Python (for Linux) or Visual Basic (for Windows) is the way to go.

----------

As for your code:
cout << a << b

Means print a then b.

You would need to use logic statements (the "if" keyword) to do either
cout << a
or
cout << b


Not cout << a << b which will print both.

And though you ask the user to enter /either/ a or b, you're requiring him to enter both.
Ok, well I tried the following code, but its still printing both no matter which letter I type:

#include <iostream>

using namespace std;

int main()
{
int a, b;

a = 4 * 6; // (Note use of comments and of semicolon) a is 24
b = a + 5; // b equals the original value of a with five added to it

cout<<"Please enter letter a or b: ";
cin>> a;
cin>> b;
if(a)a;
if(b)b;
cout<<"You entered: "<< a <<"\n";
cout<<"You entered: "<< b <<"\n";
cin.get();
}
 

mqudsi

Mostly Harmless
Staff member
#19
You need to read up on the if statement, the one you posted does nothing at all.

online C++ tutorial: Branching Statements (if, else, switch)

Programming in particular takes a lot of effort on the learner's behalf. You need to have the patience to sit there and try all the different combinations, try to see how and why something works (rather than simply what it does), and constantly, constantly, above-all research.
 
#20
Oh, I see. :smile: So the correct syntax would be:

#include <iostream>

using namespace std;

int main()
{
int a, b;

a = 4 * 6; // (Note use of comments and of semicolon) a is 24
b = a + 5; // b equals the original value of a with five added to it

cout<<"Please enter letter a or b: ";
cin>> a;
cin>> b;
cin.get();
if (a<b) {
cout<<"You entered 'a' which equals: "<< a <<endl;
}
else {
cout<<"You entered 'b' which equals: "<< b <<endl;
}

}
?

Well, that gave the correct value for a, but not for b. :?? b is saying it equals 24 instead of 29.

Addendum:

Ok...so I'm a little lost on how the "if" statement is supposed to make it display the right thing. :wtf: I understand that if the "if" statement is true, then the code that is enclosed in the braces under it is executed, but if it is false, it executes the code under the "else" statement. So how does this help me, since if I give it a correct statement, i.e.

if (a = 24) {
then it'll run the code following it, which is

cout<<"You entered 'a' which equals: "<< a <<endl;
}
but if it is false, it'll run the code under the "else" statement, like this

else {
cout<<"You entered 'b' which equals: "<< b <<endl;
}
so obviously since the statement is *true* it'll say "You entered 'a' which equals: 24" regardless of which letter is actually given (whether a or b). :wink:

And if, on the other hand, I give a statement that is *false* like this

if (a > b) {
cout<<"You entered 'a' which equals: "<< a <<endl;
}
else {
cout<<"You entered 'b' which equals: "<< b <<endl;
it'll of course return the value of 29 (which is the value that the 'b' variable was given), regardless of which letter is given in the input because the "if" statement is false, and so the program skips it and reads from the "else" statement instead. So how does this help me at all? :| I would get the same result no matter what type of operators are given in the condition of the "if" statement.

FYI, I'm trying to find a way to get the program to display the correct output depending on which variable is given.

Jake

Addendum:

Man...I am so close! :smile:

Here is what I thought would work, but unfortunately I'm having the same problem as before, i.e. with the same thing being given in the output regardless of which variable is typed in:

#include <iostream>

using namespace std;

int main()
{
int a;
int b;

a = 4 * 6; // (Note use of comments and of semicolon) a is 24
b = a + 5; // b equals the original value of a with five added to it

cout<<"Please enter letter a or b: ";
cin>> a;
cin>> b;
cin.get();
if (a > b) {
cout<<"You entered 'a' which equals: "<< a <<endl;
}
else if (a=24) {
cout<<"You entered 'a' which equals: "<<a <<endl;
}
else if (b=29) {
cout<<"You entered 'b' which equals: "<< b <<endl;
}


}
As you can see, I made the "if" statement false, so it would read from the "else if" statements (which are true), which you can supposedly have multiple of. But I'm having the same problem as before...:frowning: It wont say the correct thing when the 'b' variable is given...it still says "You entered 'a' which equals 24".
 
Last edited: