Program stuck but processing

Hello fellas again, im trying to do an square root calculator as practice, and i have done it but when i enter my number it will stuck and if i look into task manager it processing something but i dont know what, i waited 10 minutes and no respond, do someone knows why? Any recomandations will be thankful! Thanks in advance!

Code:
https://pastebin.com/jrza8xLe
(It was too long to place it here)
Why all the global variables? Your functions don't take parameters, they act on the global state of the application. Even though there are just three functions, the code is very difficult to follow.

For example, loadprimenbOp() uses orv. But it's not obvious what it is or where it's set.

Ideally, you shouldn't have any globals in this program, and the functions should be driven by their parameters. It's inevitable to have problems with this style of programming.
@kbw im quite new to C++ and idk how to use&&what (are) parameters :/
Do you mean i need to make my program more like a straight way? if yes, there are some parts in this program which i cannot do it straight, for example, i need to get back at a point to do some things again, also, thanks for answering!
int addem(int a, int b)
{
return a+b;
}

Here, a and b are parameters. Down in main it might be called by

x = (y,z); //y's value becomes a in the function body, z becomes b, x is y+z after it runs ...

this avoid having to do globals like

int a;
int b;
int result;

void add()
{
result = a+b; //this works but for anything bigger than a few lines of code you quickly run into many problems tracking the values of a and b and result which might be used in a dozen functions, changed in main, etc all without any real way to track it.
}


@jonnin
Oh, yeah, you explained it simple and very good, thanks, now i know how to use and what are parameters! :D Learning a new thing in C++ almost everyday :)

Now i wanna try to remake the entire program, until then, maybe someone can fix my older one, if i manage to make the newer one working, i will close this thread and post the code here, thanks bro!
No, I don't mean "more like a straight way", the structure is kinda ok. I'll parametrize your program later on, although it's turned out to be a little tricky because of how some variables are used across functions.
@kbw
Thanks if you will solve the program but i've done the version with paramaters from 0 already and there is the EXACT same problem, i enter the number and it do nothing after that, code is here: https://pastebin.com/VbgvgWGC
Ok.

When you declare a variable as global or static, it gets placed into a special data segment within the program that is zero'd out when the program starts. As such, these variables are initialized to zero within the program.

However, when you declare them on the stack (used to be called automatic variables), they're not initialized, and you have to do it yourself. So, for example, exitBV in main() is not initialized. The compiler should have warned you.
Last edited on
Oh, you are right about that, i'll fix it later, what about the first one? It has the same problem like this one, it gets stuck after entering the number.
As the original version just used global variable, they are all initialized to zero. I'm not sure why it was stuck.

Compilers are pretty good at warning you when things aren't quite right. It's worth paying attention to the noise they generate.
Last edited on
I figured out the problem, the program was doing an infinite loop because when i was checking for a float number i was doing the reverse, it must be: if float stop, and it was: if float continue XD, then was created the infinite loop, but theres another problem, the program overall is good but it isnt writing anything to the RNFS.txt file, and at the final calculation it isnt quite right, this isnt a problem, i'll fix it now, i will be posting the final program fixed when i will finish it! Thanks all for suggestions and help!

PS: I am fixing the version with global variables, i'll parametrize it later on.
Topic archived. No new replies allowed.