0
PIN Lock!
Hy! I wrote two versions of the simple program. Which of these codes is better? Checking the code not in sololearn! Here it works not correctly. https://code.sololearn.com/cZdr2bZkfDnW/?ref=app https://code.sololearn.com/cGMIX4xHB0on/?ref=app
3 Respuestas
+ 1
I like the second version better.
The while loop executes a loop 'until a condition becomes false', so whenever it's possible to find a condition, it will make the code more expressive.
The code becomes more like actual language:
'While input doesn't equal the password, ask again.'
One thing though:
Format!
Don't torment the eyes of people who have to read your code - make it readable yourself!
int x;
cout << "PIN Lock 1.0 \n\n";
do {
cout << "Please, enter PIN code: ";
cin >> x;
if (x != 60425) {
cout << "False!" << endl;
}
} while (x != 60425);
cout << "True!";
return 0;
+ 1
Thanks! I'm sorry! And thanks for the tip.
I'm used to saving, even though this isn't necessary)
0
Foremost you want to save time and unnecessary effort.
Statistically people spend a lot more time reading and debugging code than actually writing it.
By choosing good formatting, you will spend a little more time now, but you may save a lot of time in the long run. 😉