Overblog
Edit post Follow this blog Administration + Create my blog
Learn to Code with KC

Inputs and Outputs

All the programming that I do involves making outputs in the console.

What appears in the console is the purpose of all the coding you write. Simply, write the coding and click “run”. You will see the output in the console. Many times you will make a mistake in the program. The errors that are made are highlighted and a helpful statement telling you what you did wrong. Bug fixing is a very important skill and a skill that is needed greatly especially when trying to write a program of hundreds or thousands of lines. In order to write something to the console, an input, use cin >> variable. When the program is run you will be able to give the value of the variable. When you want something written in the console, an output, you simply use cout << whatever you want. The endl ends the line.

#include <iostream>

using namespace std;

int a;

int main()

{

cout << "Enter a number: " << endl;

cin >> a;

cout << "You entered " << a << endl;

return 0;

}

Enter a number:

4

You entered 4

Begin your programs with #include <iostream> and using namespace std. Also the main function makes the program work. Add return 0 to the end of int main().

Share this post
Repost0
To be informed of the latest articles, subscribe:
Comment on this post