1 min read
Here´s my code for the activity “Fun with numbers”
// Fun with numbers
using namespace std;
int main() {
int x;
int y;
cout
cin >> x;
cout
cin >> y;
cout
cout
cout
cout
cout
return 0;
}
Here´s a screenshot of when I ran my program
How to do it (explanation)
I started my code with #include
Then I wrote using namespace std;
Once you have done that you have to declare the function main in which you will write what is actually going to happen when you run the program.
Then you have to declare your two variables using “int” because they will contain numerical values.
Now you write the command “cout” to let the user know what you want her/him to do which in this case is two introduce a numerical value.
Now you introduce in your code the command “cin” which is the input command in c++. This let the user introduce the values for the variables that we previously declared.
Now you introduce the command “cout” again so you let the user know what mathematica operation is taking place. You have to write that text in quotes and then you just indicate the operation that you want to do with your variables using c++ operators (+ – * / %).
Remember to always use semicolon at the end of each sentence in your code (except for the first one and when declaring the variable main).
At the end you just write return 0; in order to finish your program.
I found this web page very helpful http:/
On the left side of the page you will find “Basics of C++” and I especially checked variables and types, operators, and Basic input/output. #TC1017 #WSQ03
WSQ03 Fun with numbers by Jesús Tostado is licensed under a Creative Commons Attribution 4.0 International License.