Please post anything about C++ and lots of tutorials!
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
I'm learning C# but I can still tell you some about C++. What skill level are you? Do you have input/output? How many commands do you know?
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
I know about 2 commands (I started 3 days ago.) but you probably should let me restart please also explain the commands well.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
Let's make a Hello World program.
1. If you are not using Visual C++, skip this step. Include the "stdafx.h" header. This allows everything else to be done.
#include "stdafx.h"
2. Then, we have to include the "iostream" library, which includes input, output, etc.
#include <iostream>
3. Everything in C/C++/C# and such has to be inside something. We'll start with a basic void Main variable.
void main()
4. Now let's use { and } to indicate that all of the following is inside void main.
{
5. Let's print the phrase. cout is the command for output. To print "Hello, world!," we have to do this:
std::cout<<"Hello, world!';
MAKE SURE THAT SEMICOLON IS AT THE END!!! In compiled languages, something has to tell the compiler to go to the next line. In the C languages (C/C++/C#) it's a semicolon. Also, the std:: is the namespace for cout, cin, etc. There is a shortcut we'll use later.
6. Now to end the program. We'll use a } to complete void main.
}
Our final code should look like this:
//If you aren't using Visual C++, skip the following line
#include "stdafx.h"
#include <iostream>
void main()
{
std::cout<<"Hello, world!";
}
That will compile and run, but it immediately closes. We need another command. cin.get(); will work nice. I'll explain what it does in a later tutorial.
#include "stdafx.h"
#include <iostream>
void main()
{
std::cout<<"Hello, world!";
std::cin.get();
}
There you go! it will print "Hello, world!" and wait for a keypress!
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
By the way on my version you have to do int main instead of void main.
But it helped me!
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
By the way on my version you have to do int main instead of void main.
But it helped me!
Int and void are two different... things. I forgot their term. I would expect you could use void as well. Void is another "print something on the screen" thing in the program, I believe.
Now to make this post another use.
This is a review of what @IAmAPersson posted earlier of COUT. If you need another example it is here.
COUT is the way to print output on the screen in a C++ program. Here's my example for COUT:
#include <iostream>
using namespace std;
int main()
{
cout << "Boy I love bacon"
return 0;
}
There is another command like COUT, which is CIN, which accepts input. If someone could go over that I forgot how.
I also am interested in developing small games in C++. If anyone has tutorials on that it would be SUPER helpful.
Part 1: A Concept Changed
(get it?)
Alright, why not make more tutorials and give them a name? Like the Coinz Tutorials in the PTC forums.
So here's an if else statement here.
You might be thinking "WOAH, slow down 0Games!" don't worry, I can go over variables first.
So variables. Seen in every programming language in the history of programming, variables are one simple thing: placeholders. They are VERY important.
You can do many things with variables, but I won't show them all. Now, variables.
To make a variable, you simply put the type in front, like this:
int
I'll use an integer for the type as of now. Next, you input what you want it to hold; numbers, text, many things. I'm going to put the text "bacon" in mine. You don't have to use bacon- use whatever you want for your variable.
int variable();
I almost forgot, use whatever variable name you want. Now, do this-
variable="bacon";
There is another way to declare variables. You can declare it all in one line like this:
int variable = "bacon";
It is important to put the semicolon after.
I prefer the two line way, honestly. But if you prefer to put it all in one line that is also a great way to declare variables.
Now you can print your variable like this-
cout variable;
Easy, right? It's a really useful thing to know. Next time I'll show you if statements. See you later and enjoy your knowledge!
Int is for integers, string (under the string library) is for strings. There is also bool, float, and double. A string can be done like this:
#include <iostream>
#include <string>
void main(){
string myString="A string can go here!";
cout<< myString;
}
An "int" holds an integer, like 5, 25, 82, 5482, etc. A "float" is a floating decimal integer, like 5.537, 42.278, 4289.2890, etc. A "double" is a double precision floating decimal. That should be self explanatory. A "bool" (full name "boolean") is a true/false statement. you can do this by doing:
bool myBoolean=true;
Tada!
EDIT: How accurate is a float vs. a double? If I assigned Pi to an int, here's what I would get:
3
If I assigned it to a float, here's what I would get:
3.1415927
If I assigned it to a double, I would get:
3.141592653589793
Now, if you really need to get precise, you can store it as a string, and convert when needed later. Here's Pi as stored in a string:
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
Hey is there anything like a WAIT command from PTCom?
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
@GraphicGenius if you have a Windows computer, there should be a library called Windows.h. Include it by doing this:
#include <Windows.h>
Then the command is Sleep. Try as hard as you can to avoid it though. The syntax:
Sleep(milliseconds);
1000 milliseconds is 1 second, so
Sleep(1000);
Is the PTC equivalent of
WAIT 60
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
Int is for integers, string (under the string library) is for strings. There is also bool, float, and double. A string can be done like this:
#include <iostream>
#include <string>
void main(){
string myString="A string can go here!";
cout<< myString;
}
An "int" holds an integer, like 5, 25, 82, 5482, etc. A "float" is a floating decimal integer, like 5.537, 42.278, 4289.2890, etc. A "double" is a double precision floating decimal. That should be self explanatory. A "bool" (full name "boolean") is a true/false statement. you can do this by doing:
bool myBoolean=true;
Tada!
EDIT: How accurate is a float vs. a double? If I assigned Pi to an int, here's what I would get:
3
If I assigned it to a float, here's what I would get:
3.1415927
If I assigned it to a double, I would get:
3.141592653589793
Now, if you really need to get precise, you can store it as a string, and convert when needed later. Here's Pi as stored in a string:
EDIT EDIT: That may not be accurate, as the info was gotten from a Java program
Interesting. I got all that from the Bucky Roberts tutorials, but he used CodeBlocks rather than Visual C++.
I have a new problem. I try to run a C++ program and I'm running Visual C++, but when I run it, in the console below it says it has an error when, to my skill level, I see no discrepancies in the code. See if anyone else can find this issue (I'm honestly looking at you, Persson)
#include <stdafx.h>
#include <iostream>
void main()
{
cout<<"I love bacon";
return 0;
}
EDIT: And Persson, you don't need to declare the type of variable again if you do it in two lines. For example:
int variable();
variable="Hello";
That would work I believe, unless it doesn't. I haven't used this language in a long time after I watched a few tutorials from Bucky Roberts (Which I got from a Windows 8 app, not that video mentioned)
@0Games CodeBlocks must be the Visual Basic of C++, cause that barely resembles C++. If I were to do what you mentioned in normal C++, I would get an illegal type error. In normal C++, you also don't need to use a () after a variable, like:
int myVariable;
//as opposed to
//int myVariable();
Anyway, please try to post tutorials on normal or Visual C++. What you are posting is kinda like posting Java tutorials on a C# thread.
EDIT: about your problem. I see two errors. First off, stdafx.h needs to be in "" rather than <>
#include "stdafx.h"
Second, a return value is not needed if you are doing void main(). It is, however, if you are doing int main(void).
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
Also, if you speak German, here's a wonderful community for learning C/C++/C#/Java! Go here! You might find me on there occasionally.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
@IAmAPersson I am using an app and the only include thing that it can do is iostream.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
@GraphicGenius You can only get serious about C++ when you get a true compiler. iostream is only used for console applications, which accounts for about 1% of C++ programming. Plus, even when using console applications, I use a good bit of libraries, such as stdlib.h, time.h, Windows.h, string.h, string, etc.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
Forums
Topic: C++ Thread
Posts 1 to 20 of 29
This topic has been archived, no further posts can be added.