What's wrong with my code? It gets giving error "[Error] ld returned 1 exit status"

0

Get any value and ask the user if this value is in dollars or in reais. If they are dollars, convert them to reais. If they are real, convert them to dollars. Repeat the operation until the sum of the values entered is greater than 10,000.

#include <stdio.h>
#include <conio.h>

    int main(){

        float x,dr, xf, xs=0;//numero inserido, dolar ou real, numero convertido, conversao somada
        while(xs<=10000){

            printf("Digite o valor");
            scanf("%f",x);

            printf("Digite 1 para converter para dolar, e 2 para converter para real");
            scanf("%f",dr);

            if (dr=1) {
                xf=x*3.58;
                prinft("O valor em dolar e %.2f",x);
            }

            if (dr=2){
                xf=x/3.58;
                printf("O valor em reais e %.2f",x);
            }

            xs=xs+xf;
        }
        getch();
        return 0;
    }
    
asked by anonymous 09.04.2016 / 04:39

1 answer

1

The second parameter of the scanf() ( refer to its documentation ) is the memory address of where the value of your variable is stored, to obtain the address of the variable, the & commercial is used.

See your modified code:

#include <stdio.h>
#include <conio.h>

int main(){

    float x = 0, dr = 0, xf = 0, xs=0;//numero inserido, dolar ou real, numero convertido, conversao somada

    while(xs<=10000){

        printf("\nDigite o valor");
        scanf("%f", &x); /*<----- Mudei aqui*/

        printf("\nDigite 1 para converter para dolar, e 2 para converter para real");
        scanf("%f", &dr)  /*<----- Mudei aqui*/;

        if (dr == 1) {  /*<----- Mudei aqui*/
            xf=x*3.58;
            printf("\nO valor em dolar e %.2f",x);  /*<----- Mudei aqui*/
        }

        if (dr == 2){  /*<----- Mudei aqui*/
            xf=x/3.58;
            printf("\nO valor em reais e %.2f",x);
        }

        xs=xs+xf;
    }

    getch();

    return 0;
}

See this warning:

  

... \ resp.c | 11 | warning: format '% f' expects argument of type 'float *',   but argument 2 has type 'double' [-Wformat =] |

It indicates that you should get a float * which is the pointer, the location of the content of your variable passed in the argument, try to enable all warnings in your compiler . There was also a typo in the function printf() you entered prinft() so your program will not compile, and in if condition you used = instead of == which is for comparisons. You do not need your variable dr to be float since it's just to set the chosen option, you can use an integer variable for this.

    
09.04.2016 / 05:01