Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Error when compile program

Lukas

New Coder
Hello guys Can someone help me with the program,. Code in C i have right down but when i try to compile, every time there is an error: ‘temp1’ is used uninitialized in this function int gamefield[temp1*2];
compile start by gcc -std=c11 -Werror -Wall -lm

Thanks for some help :( im like beginner in programming



C:
#include <stdio.h>
#include <stdlib.h>

#define VAR 0.00000000001

int main(){
    int temp1,temp2;
    int spins = 0;
    int a = 0;
    int b = 0;
    double infinity = 10000000;
    double summary = 0x00;
    double count = 0x00;
    int gamefield[temp1*2];
    int surface[temp1];
    int temp3[temp1];

    scanf("%d %d",&temp1,&temp2);
    
    while(spins != temp1*2)
    {
        scanf("%d",&gamefield[spins]);
        spins++;
    }
/////////////////////////////////
     /*if(temp3[y+1] < temp3[y])
            {
                int temporary = temp3[y+1];
                temp3[y+1] = temp3[y];
                temp3[y] = temporary;
                temporary = surface[y+1];
                surface[y+1] = surface[y];
                surface[y] = temporary;
            }*/


    //////////////////////////////////////////////////////

    for(int z = 0; z < temp1 * 0x02 ; z++)
    {
        if(z == 0x00 || z % 2 == 0x00 )
        {
            surface[a] = gamefield[z];
            a++;   
        }
        else
        {
            temp3[b] = gamefield[z];
            b++;
        }
    }
    //////////////////////////////////////////////////////

    for(int x = 0; x <temp1 - 1; x++)
    {
        for(int y = 0;y<temp1 - 1; y++)
        {
            if(temp3[y+1] < temp3[y])
            {
                int temporary = temp3[y+1];
                //printf("%.9lf\n",temp3);
                temp3[y+1] = temp3[y];
                temp3[y] = temporary;
                //printf("%.9lf\n",temp3);
                temporary = surface[y+1];
                surface[y+1] = surface[y];
                surface[y] = temporary;
            }
        }
    }
    double najmensia = temp3[0x00];
    najmensia *= -1;
    ///////////////////////////////////////////////////////

    while(infinity - najmensia > VAR ){
        count = (najmensia + infinity) / 2.0;
        summary = 0.0;
        for(int i = 0;i<temp1;i++){
            //printf("%.9lf\n",count);
            summary = summary + surface[i] / (temp3[i] + count);
        }
        if(summary < (double)temp2){
            //printf("%.9lf\n",count);
            infinity = count;
        }
        else if(summary > (double)temp2){
            //printf("%.9lf\n",count);
            najmensia = count;
        }
        else{
            break;
        }
    }
    printf("%.9lf\n",count);
    return 0;
}
/*
3 5
4 -1
4 0
10 3*/
/*
4 10
5 3
2 2
3 6
3 1*/
 
@Lukas, when the compiler says something is "uninitialised", it means that you haven't initialised your variables with a value. In this case, you need to go back and give both temp1 and temp2 values.

Alternatively, you can remove the -Werror -Wall arguments, and that permits the program to be compiled. You can see what these arguments do here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options

If none of this is what you're looking for, please let me know.
 
Back
Top Bottom