What’s wrong with my code? It keeps giving error "[Error] Ld returned 1 Exit status"

Asked

Viewed 281 times

0

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

#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;
    }
  • In function scanf() the second parameter and the memory address of your variable, you must enter the address using the &, see: scanf("%f", &dr);.

  • Man, I changed that but still gives the msm error :/

  • I answered your question.

1 answer

1

The second function parameter scanf() (see her documentation) is the memory address from which the value of its variable is stored, to obtain its address the & commercial.

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 (warning):

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

It indicates that you should receive one float * which is the pointer, the location of the contents of its variable passed in the argument, try to enable all warnings of your compiler. There was also a typo in the function printf() you typed prinft() so your program will not compile, and in condition if you used the = instead of == which is for comparisons. No need for your variable dr be a float since it is only to set the chosen option, you can use an integer type variable for this.

  • 1

    Hey, man, it worked out now. But there is only one problem, when I type if I want to convert to real or to dollar, it answers me the 2, in dollar and in real. you know what can be?

  • I didn’t realize you used = instead of =, I’ll edit the answer.

  • edited the answer.

  • 1

    Ahh yes, thanks man. vlw same kk. eh q I’m starting now with this, and eh a little confused still kkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.