Friday, September 16, 2016

Getting good at: C++ | #4 - User-defined variables.

4 - Typing in stuff and outputting a result

ello blazers NFKRZ ere and today we're going to cover User-defined variables. So you guys know about cout << which outputs text or variables on the screen. What you guys don't know is that there's a way to INPUT text, with cin >>. Now, this doesn't mean you can just do this:

int main()
{
     cin >> "top kek m8";
     return 0;
}

Don't be lazy. If you're gonna input text, include a string. I'll cover that in the next post. For now, I'm gonna show you how to make a basic user-defined variable. So you want to make a variable:

{
     int a;
     cin >> a;
}

Now, we're going to use cin to input what the variable will equal:

{
     int a;
     cin >> a;
     return 0;
}

Now, let's output the variable:
{
     int a;
     cin >> a;
     cout << a;
     return 0;
}

And you should see something like this:

Note that the '69' on the top is our input, and our '69' at the bottom is our output, meaning we set the variable to '69', and we made it output '69' on the screen with cout. That's all for today. Until next time...



No comments:

Post a Comment