0

I'm new(-ish) to C++, and I'm trying to learn something new every day. Today I'm trying to figure this out.

Do I have to check if Valmis == 1 so it won't continue/return before Realtest() is complete?

This is just an example.

int valmis = 0;

void test::Main()
{
    //just some basic stuff

    do
    {
        if (!strcmp())
        {
            //here too
            float testing = 0;
            printf("Test?  1=do it  Else=Nothing\n");
            scanf(" %f", &testing);

            if (testing == 1)
            {
                Realtest();
                //Realtest needs to be completed before continuing
                if (valmis == 1) //Do I need this or does it continue after RealTest() is complete without this?
                return (somethingmate = true);                                                 
            }
            else
            {
                return (somethingmate = true);
            }
        }

    } while();

    return (somethingmate = false);
}

void test::Realtest()
{
    //doing something here that I need to do before continuing in main/letting somethingmate to become true
    valmis = 1; //do i need this?
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Dandeson
  • 1
  • 1
  • 2
    Aside: You have `=` and `==` mixed up. Compilers warn in both cases with an adequate warning level. – chris Sep 03 '21 at 15:20
  • ^those and learn to use a debugger. It will greatly increase the speed you learn c++ and avoid a lot of frustration. – doug Sep 03 '21 at 15:21
  • What does the line `~~~~` do in c++? –  Sep 03 '21 at 15:34
  • ~~~~ was "something" aka not defined what there was going on, fixed few mix ups and typos, my real question is do i need "float valmis" and use it as check when going to Realtest? i need it to complete before "return (somethingmate = true);" takes place,aka i dont wanna continue in main before Realtest is done, after that main can return. – Dandeson Sep 03 '21 at 15:45
  • @LaD1ckersson write `int` instead of `float`. See https://stackoverflow.com/questions/2100490/floating-point-inaccuracy-examples for reason. And you don't need `if(valmis == 1)` since valmis is a global variable and it is assigned 1 in `Realtest()`, so the condition valmis == 1 is aways true. – susanth29 Sep 03 '21 at 15:59
  • `if (!strcmp())` shouldn't even compile. Also please mark comments as comments with `//`. Don't put random text in the code, this makes it hard top read. – Lukas-T Sep 03 '21 at 16:17
  • @churill this is not the original code, this is kinda "censored" version of it and not my question when it comes to compiling. – Dandeson Sep 03 '21 at 16:34
  • @susanth29 thank you for your answer, my question being if i remove "if(valmis == 1) does it continue going? i don't want main continue from that point before "Realtest()" changes "valmis" to 1, does it "pause" without that check? because if i choose to use Realtest it has to complete before main can set "somethingmate" to true – Dandeson Sep 03 '21 at 16:36
  • The code after a function call is run after said function returns. Parallel code execution can be achieved through multithreading, but it is not the default. – Quentin Sep 03 '21 at 16:39
  • with or without `if(valmis == 1)` the main process continues only after Realtest() is completed. And also change the type of `testing` to `int` for the same reason as above. – susanth29 Sep 03 '21 at 16:43
  • @susanth29 that's all i needed to know, thank you so much and have a great day :) Edit: should i delete this messy post or do you wanna answer it? – Dandeson Sep 03 '21 at 17:57

0 Answers0