简体   繁体   中英

errors during compilation of the code

this is the top portion of my program My code runs perfectly on my Dev-C++ compiler but when i ran the same code on ge edit it showed three errors

1.unused variable d
    double d =round(j);
           ^
2. unused variable d
    double d =round(j);
           ^
3.unused variable i
    float i= (float) round(j);
          ^

how is it possible that the same code works in one compiler but not work in other?

#include <stdio.h>
#include <math.h>

double round(double d);

int main() {
    float j;
    int c = 0;
    printf("how much change is owed? \n");

    scanf("%f", &j);

    double d = round(j);
    float i = (float)round(j);

    while (i < 0) {
        printf("amount of money \n");

        scanf("%f", &j);
        double d = round(j);
        float i = (float)round(j);
    }
    // more code ...

    return 0;
}

These three variables double d, double d, and float i are not used. They are only defined and it is totally unclear why they were defined

  double d =round(j); // <== ???
  float i= (float) round(j);


    while(i<0)

    {    printf("amount of money \n");

        scanf("%f",&j);
        double d =round(j); // <== ???
        float i= (float) round(j); // <== ???
   }

So the error messages are clear enough. They are self explained.

I think that in the last marked statement you meant (inside the loop)

    i= (float) round(j);

Definately.

Eg. Some code is windows-specific and other code is linux specific (dealing with files for example). So code would compile on a windows compiler and not a linux compiler.

There are even different versions of C (look up gnu90 vs. c99 vs. c11) because the specification has changed over time.


Your "error" however is a compiler warning you that you are not using 3 variables you assigned. This is typical of an error so you should go double check.

It is perfectly valid C and should still compile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM