C++ beginners' problem with program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ beginners' problem with program

Hello :) i want my program to give its user 3 chances (at max) to give corect number (e.g. PIN as it is supposed to be an atm sim) and i dont really know how do i make it happen. Im thinking if the "for" loop is the correct path to take.

21st Jun 2018, 12:19 PM
Michał
Michał - avatar
8 Answers
+ 4
1.here size_t means unsigned int so pin can't be negative. 2.pin{1234} means pin = 1234.....same goes for _try. 3.and constexpr will just replace the values at compile time for example after compiling the while loop will look like while(_try != 3){....} you will learn this things better once you start using them in your code.
21st Jun 2018, 1:22 PM
Tanay
Tanay - avatar
+ 3
yes , you can surely use for loop.........do you want the code or logic......did you tried anything?
21st Jun 2018, 12:28 PM
Tanay
Tanay - avatar
+ 2
freaxys how about this? I currently set the pin = 1234 https://code.sololearn.com/cxzhfHkbNXsh/?ref=app
21st Jun 2018, 12:52 PM
Tanay
Tanay - avatar
+ 1
To make it clear you can use a do-while-loop: do{ add attempt; get number; compare numbers; }while(number is not epual or about 3 attempts)
21st Jun 2018, 12:28 PM
XiLef
+ 1
Loops are always a good choise if you use code multiple times.
21st Jun 2018, 12:38 PM
XiLef
+ 1
Tanay ay thanks man that really helps :)
21st Jun 2018, 2:19 PM
Michał
Michał - avatar
0
as i said im just begining my adventure with programming so the first thing ive tried was simple if else conditionals wich i quickly erased because it felt bad to use it so then i had the idea to use switch but you cant use variables there. and now i have the idea to use loops and use maybe 'break' function in it. can i do something like that? im sorry i dont have the source code because im coding on laptop :/
21st Jun 2018, 12:36 PM
Michał
Michał - avatar
0
Tanay this part of the code is new to me https://code.sololearn.com/ccVD2IL7QEx8/?ref=app
21st Jun 2018, 1:08 PM
Michał
Michał - avatar