Welcome to Coders Corner! This is a topic where fellow programmers can talk about programming, what programs they are working on, and help each other out! Just post a profile with the languages you know and how long you have been programming. Here's my profile: Name: Diglett809 Languages: C++, Java, Python, Visual Basic Years of Experience: 3
~l)~/\/~/-\~ The tie between real life and legos is imagination .
Welcome to Coders Corner! This is a topic where fellow programmers can talk about programming, what programs they are working on, and help each other out! Just post a profile with the languages you know and how long you have been programming. Here's my profile: Name: Diglett809 Languages: C++, Java, Python, Visual Basic Years of Experience: 3
I know about Assembly Code and Pascal code, but not as much about C++, Java, Python or Visual Basic. I may learn these languages in the future.
Post by masterlegobuilders on Jan 10, 2017 22:30:52 GMT
Hi, I'm MLB and I would be learning C# had my school not stopped the after school club where it was taught Technically I have a years experience, but I payed NO attention
My main skill is bugfixing, something that I can do with basic knowledge of the language. I don't know how, but I can Also, later this year I will be learning basic HTML.
I would love to learn from you guys so post any code you find interesting or is really basic
One mod to rule them all and in the darkness ban them - Lord of the Mods "I am the Mod Reborn!" - masterlegobuilders I'm the real boss
Welcome to Coders Corner! This is a topic where fellow programmers can talk about programming, what programs they are working on, and help each other out! Just post a profile with the languages you know and how long you have been programming. Here's my profile: Name: Diglett809 Languages: C++, Java, Python, Visual Basic Years of Experience: 3
I know about Assembly Code and Pascal code, but not as much about C++, Java, Python or Visual Basic. I may learn these languages in the future.
I have heard of Pascal. It's even older than C++ as they talk about it in my book which was made in 1991:O! I don't recommend Visual Basic at all, I hated it:P. Python is good if you are just starting, but that's about it. Java and C++ are great languages and I suggest trying them sometime:).
~l)~/\/~/-\~ The tie between real life and legos is imagination .
Yikes I'm the worst in the world at programming. You can help me in my exams.
Do you take a class? If you are learning one of the languages I know, I will gladly help. When I was in school I literally helped everybody at my table with the work, so I'm used to it:P.
~l)~/\/~/-\~ The tie between real life and legos is imagination .
Hi, I'm MLB and I would be learning C# had my school not stopped the after school club where it was taught Technically I have a years experience, but I payed NO attention
My main skill is bugfixing, something that I can do with basic knowledge of the language. I don't know how, but I can Also, later this year I will be learning basic HTML.
I would love to learn from you guys so post any code you find interesting or is really basic
That's terrible! Who gets rid of programming classes, programming is the future of the world:O! I don't know HTML, but I heard it was pretty easy to learn quickly. I might learn the basics someday when I'm bored:P. I will post one of my test projects I just made in C++, assuming it fits in a post;).
~l)~/\/~/-\~ The tie between real life and legos is imagination .
Here's a program I made to get used to C++ coding again: // Test.cpp : A test program //
#include "stdafx.h" #include <iostream>
int main() { int num; const int n1 = 12, n2 = 51, n3 = 103, n4 = 199, n5 = 261; int nums[] = { n1, n2, n3, n4, n5 }; for (int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) { std::cout << i + 1 << " " << nums << std::endl; }
std::cout << "A number from the list: "; std::cin >> num; switch (num) { case n1: std::cout << "You chose the first number which is " << n1 << std::endl; break; case n2: std::cout << "You chose the second number which is " << n2 << std::endl; break; case n3: std::cout << "You chose the third number which is " << n3 << std::endl; break; case n4: std::cout << "You chose the fourth number which is " << n4 << std::endl; break; case n5: std::cout << "You chose the fifth number which is " << n5 << std::endl; break; default: std::cout << "The number you entered isn't on the list" << std::endl; } return 0; }
I will explain it now. First of all, all programs MUST have a "main" function. The the code in the curly braces is executed when the program runs. In this program it's the only function, but you can have more. For this program I just used the "int" data type. It is just a number with no decimals that isn't too big. I forget the exact size it can go up to. If you need a bigger integer, you can use "long". So I have num, which is the variable input from the user, of type int. Then I define 5 other int constants. Constants are variables that cannot be changed in the program. I then put them in an array named nums. To define an array you put "[]" after the type and name. You can also put a number in the brackets to define the size of the array. I didn't do this as I put in all the values manually, but if I did, it would be 5. Then I made a for loop that iterates through the array. The code "sizeof(nums) / sizeof(nums[0])" may look complicated, but all it really does is get the size of the array, or 5. Then I print out a 5 number list from the array. Arrays start at 0, which is why I did "+1" on the number, that way the list is "1-5" rather than "0-4". "cout" prints to the console. "endl" creates a new line. I had to do "std::" in front of them because it's an outside class. I could have sworn there was a way to make it so you can do it without that, but I forget what it is and couldn't find it on the internet:P. Then I print a message prompting the user for a number to the console. Then I have "cin" which gets user input. In other words, the user types a number and it gets stored in num. I then do a switch to decide which message to print. The variable in parenthesis after switch is the variable being tested. So for example, if I typed 12 it would do case n1 as n1 is set to 12. It would then go on to print the code after the case up until "break". What break does is exit the switch statement, and in this case, finish the program. If a number that isn't on the list is input, the "default" statement would print instead. I don't need a break after default as it's the last statement of the switch. Switches don't require a default, but it's usually good to do one. The program ends with the line "return 0". Since main has "int" before it, it requires a return of an int to be done at the end of the program. Generally the int returned is 0, I am yet to use another int for any reason. Lastly, all statements in C++ must end in a ";". Also, "#include" imports another class or class library. In this case I used "iostream" which allows for input and output. In other words, you need to import it to use cout and cin. That's about it for this program! If you have any questions about it feel free to ask:).
~l)~/\/~/-\~ The tie between real life and legos is imagination .
I have been messing around with various languages since I was seven
Old sci-fi is the best sci-fi! v this is not old sci-fi Maxim 3: An ordnance technician at a dead run outranks everybody. Maxim 24: Any sufficiently advanced technology is indistinguishable from a big gun.
"“Even by the twenty-second century, no way had yet been discovered of keeping elderly and conservative scientists from occupying crucial administrative positions. Indeed, it was doubted if the problem ever would be solved.” ^That, on the other hand, is old sci-fi.
YAY! My dad reminded me how to get rid of the "std::" before cout, cin, and endl! You must type "using namespace std;" at the top of the program with the imports:D! I totally forgot about this, but now that I am reminded of it, it has come back to me:D! There are also other namespaces, but I have only ever used std.
~l)~/\/~/-\~ The tie between real life and legos is imagination .
**Breaks out notebook and starts aggressively taking notes.**
I should be programming teacher. That was the most fun I had making a post in a long time:O:P! I guess I really enjoy explaining programming and writing teachable programs:).
~l)~/\/~/-\~ The tie between real life and legos is imagination .
Here's a program I made to get used to C++ coding again: // Test.cpp : A test program //
#include "stdafx.h" #include <iostream>
int main() { int num; const int n1 = 12, n2 = 51, n3 = 103, n4 = 199, n5 = 261; int nums[] = { n1, n2, n3, n4, n5 }; for (int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) { std::cout << i + 1 << " " << nums << std::endl; }
std::cout << "A number from the list: "; std::cin >> num; switch (num) { case n1: std::cout << "You chose the first number which is " << n1 << std::endl; break; case n2: std::cout << "You chose the second number which is " << n2 << std::endl; break; case n3: std::cout << "You chose the third number which is " << n3 << std::endl; break; case n4: std::cout << "You chose the fourth number which is " << n4 << std::endl; break; case n5: std::cout << "You chose the fifth number which is " << n5 << std::endl; break; default: std::cout << "The number you entered isn't on the list" << std::endl; } return 0; }
I will explain it now. First of all, all programs MUST have a "main" function. The the code in the curly braces is executed when the program runs. In this program it's the only function, but you can have more. For this program I just used the "int" data type. It is just a number with no decimals that isn't too big. I forget the exact size it can go up to. If you need a bigger integer, you can use "long". So I have num, which is the variable input from the user, of type int. Then I define 5 other int constants. Constants are variables that cannot be changed in the program. I then put them in an array named nums. To define an array you put "[]" after the type and name. You can also put a number in the brackets to define the size of the array. I didn't do this as I put in all the values manually, but if I did, it would be 5. Then I made a for loop that iterates through the array. The code "sizeof(nums) / sizeof(nums[0])" may look complicated, but all it really does is get the size of the array, or 5. Then I print out a 5 number list from the array. Arrays start at 0, which is why I did "+1" on the number, that way the list is "1-5" rather than "0-4". "cout" prints to the console. "endl" creates a new line. I had to do "std::" in front of them because it's an outside class. I could have sworn there was a way to make it so you can do it without that, but I forget what it is and couldn't find it on the internet:P. Then I print a message prompting the user for a number to the console. Then I have "cin" which gets user input. In other words, the user types a number and it gets stored in num. I then do a switch to decide which message to print. The variable in parenthesis after switch is the variable being tested. So for example, if I typed 12 it would do case n1 as n1 is set to 12. It would then go on to print the code after the case up until "break". What break does is exit the switch statement, and in this case, finish the program. If a number that isn't on the list is input, the "default" statement would print instead. I don't need a break after default as it's the last statement of the switch. Switches don't require a default, but it's usually good to do one. The program ends with the line "return 0". Since main has "int" before it, it requires a return of an int to be done at the end of the program. Generally the int returned is 0, I am yet to use another int for any reason. Lastly, all statements in C++ must end in a ";". Also, "#include" imports another class or class library. In this case I used "iostream" which allows for input and output. In other words, you need to import it to use cout and cin. That's about it for this program! If you have any questions about it feel free to ask:).
Here's a sample output for this code: 1 12 2 51 3 103 4 199 5 261 A number from the list: 199 You chose the fourth number which is 199 Press any key to continue . . .
The number "199" after the ":" is my input I typed in:). The "Press any key to continue . . ." is default after every program executes.
~l)~/\/~/-\~ The tie between real life and legos is imagination .
Hi, I'm MLB and I would be learning C# had my school not stopped the after school club where it was taught Technically I have a years experience, but I payed NO attention
My main skill is bugfixing, something that I can do with basic knowledge of the language. I don't know how, but I can Also, later this year I will be learning basic HTML.
I would love to learn from you guys so post any code you find interesting or is really basic
Do you want the code for my trollish python "chatbot"?
Old sci-fi is the best sci-fi! v this is not old sci-fi Maxim 3: An ordnance technician at a dead run outranks everybody. Maxim 24: Any sufficiently advanced technology is indistinguishable from a big gun.
"“Even by the twenty-second century, no way had yet been discovered of keeping elderly and conservative scientists from occupying crucial administrative positions. Indeed, it was doubted if the problem ever would be solved.” ^That, on the other hand, is old sci-fi.