0

After learning syntax, how does one take a real worl problem and turn it into code?

from noob to master

14th Aug 2018, 5:08 AM
Eric Fernandez
Eric Fernandez - avatar
6 Respostas
+ 1
You can compile an executable exe file
14th Aug 2018, 5:23 AM
Andrey Stepanov
Andrey Stepanov - avatar
+ 1
It's c++ code?
14th Aug 2018, 7:22 AM
Andrey Stepanov
Andrey Stepanov - avatar
+ 1
for (i=1... it's error! for ( int i = 1... it's true and.. cout << square << endl;
14th Aug 2018, 1:07 PM
Andrey Stepanov
Andrey Stepanov - avatar
0
You just take a problem in real life and then you try to recreate all of its functions in your code eg. a math formula which you find hard to calculate by yourself or just search the internet i found : write a function that finds all perfect squares (1*1 or 1 2*2 or 4) in a given range if I have a problem like this, I am looking for a formula to calculate the answers easy (1-4-9-16) (1+3=4 4+(3+2)5=9 9+(3+2+2)7=16) so you need a start range and end range input (like 3 - 5) (i thought in c++ it was cin not sure) var start = cin(); var end = cin(); (sorry for bad c++ skills) then define what p is the easiest way to do that is with a for loop var p = 3; for (i=1; i<start; i++){ p+=2; } now that we did that, we just have to calculate the square in the range which is also the easiest with a for loop var start = cin(); var end = cin(); var square = start*start; print(square); var p = 3; for (i=1; i<start; i++){ p+=2; } for (i=start; i<end; i++){ square+=p; print(square); } thats how I do that things
14th Aug 2018, 7:13 AM
Roel
Roel - avatar
0
sorry, no I'll write it again but im not good at c++ first code piece int start; cin >> start; int p = 3; for(i=0; i<start; i++) { p+=2; } the second part int start; int end; cin >> start; cin >> end; int square = start*start; cout << square; int p = 3; for (i=1; i<start; i++) { p+=2; } for (i=0; i<end; i++) { square+=p; cout << square; p+=2; }
14th Aug 2018, 7:55 AM
Roel
Roel - avatar
0
I guess the language shouldn't matter. but I guess what I'm askingbis-when I find a problem how do I learn to convert it to code. for example: I want to built a small chess game in c++ but I do know where or how to start
14th Aug 2018, 2:58 PM
Eric Fernandez
Eric Fernandez - avatar