Calling function with different arguments produces the same output. (C) : <p>I'm trying to make a program to generate 2 random numbers and print them to the screen. This is achieved by calling the Numbers function twice and assigning the value to num1 and num2 then calling PrintMsg twice also with those variables but instead the function prints the first value twice. </p>

<p>In the debugger num1 and num2 are being set to 2 different numbers and the mode variable is being successfully passed through to the PrintMsg function.</p>

<pre><code>// C program to generate random numbers 
#include &lt;stdio.h&gt; 
#include &lt;stdlib.h&gt; 
#include &lt;stdbool.h&gt; 
#include&lt;time.h&gt; 

int Numbers() {

    bool valid = false;
    int randNum;

    srand(time(0)); 

    while(valid != true) {

        randNum = rand() % 100;

        if (randNum &gt; 0 &amp;&amp; randNum &lt;= 6) {
            valid = true;
        } 
    }

    return(randNum);
}

void PrintMsg(int x, int mode) {

    if (mode == 1) {

        switch(x) {

            case 1:
                printf(" %d ", x);
                break;

            case 2:
                printf(" %d ", x);
                break;

            case 3:
                printf(" %d ", x);
                break;

            case 4:
                printf(" %d ", x);
                break;

            case 5:
                printf(" %d ", x);
                break;

            case 6:
                printf(" %d ", x);
                break;
        }
    }

    else if (mode == 2){

        switch(x) {

            case 1:
                printf(" %d ", x);
                break;

            case 2:
                printf(" %d ", x);
                break;

            case 3:
                printf(" %d ", x);
                break;

            case 4:
                printf(" %d ", x);
                break;

            case 5:
                printf(" %d ", x);
                break;

            case 6:
                printf(" %d ", x);
                break;


        return;
    }
}

int main(void) 
{ 
    int num1;
    int num2;

    num1 = Numbers();

    PrintMsg(num1, 1);

    num2 = Numbers();

    PrintMsg(num2, 2);

    return 0; 
}
</code></pre>

<p>Thanks.</p>
