PDA

View Full Version : Can't Compile



PostChache
November 20th, 2009, 09:01 PM
For some reason gcc test.c -o 123 isn't making an executable file. It'll compile it but I can't do ./123 This use to work and I don't know what happened. Any ideas?

Okay actually for some reason whenever I compile this program it doesn't make an executable file so I don't know what's wrong with it because it was working last night.

This is the code that I'm trying to compile


#include <stdio.h>
const double k_ftc = (1.8 * n) + 32; //Fahrenheit to Celsius
const double k_ctk = 273.16; //Celsius to Kelvin
void Tempature(double n);

int main(void)
{
double F;
int status;
printf("Hello, let's convert Fahrenheit to Celsius, then Celsius to Kelvin!\n");
printf("Please enter the tempature in Fahrenheit\n");
status = scanf("%lf", &F);
while (status == 1)
{
Tempature(F);
printf("If you would like to continue type in a new tempature, or enter q to quit.\n");
status = scanf("%lf", &F);
}
return 0;
}

void Tempature(double n)
{
printf("%.2lf Fahrenheit is %.2lf Celsius which is %.2lf Kelvin.\n", n, k_ftc, k_ftc + k_ctk);
}

Slimbo
November 20th, 2009, 09:14 PM
main.cpp:2: error: ‘n’ was not declared in this scope

Get rid of all the errors and you should be fine.

PostChache
November 20th, 2009, 10:01 PM
main.cpp:2: error: ‘n’ was not declared in this scope

Get rid of all the errors and you should be fine.

I've fixed it, but my real question is why is it that it would make an executable before even though it had this error?

Tony Flury
November 20th, 2009, 11:03 PM
It would never have worked - a const defines a constant value - and you were trying to use to define a formula :


const double k_ftc = (1.8 * n) + 32; //Fahrenheit to Celsius


Depending on the value of n this would create a single fixed value and the output would always be exactly the same - regardless of the input.

If you want to define a formula - use a function.

Arndt
November 20th, 2009, 11:16 PM
I've fixed it, but my real question is why is it that it would make an executable before even though it had this error?

If there are compilation errors, the output file shouldn't be created at all. If there are linking errors, it is created but then not made executable. Maybe at some point you had linking errors but not compilation errors.

(It's spelled "temperature", by the way.)

PostChache
November 21st, 2009, 11:47 AM
It would never have worked - a const defines a constant value - and you were trying to use to define a formula :


const double k_ftc = (1.8 * n) + 32; //Fahrenheit to Celsius


Depending on the value of n this would create a single fixed value and the output would always be exactly the same - regardless of the input.

If you want to define a formula - use a function.

Okay thank you.


If there are compilation errors, the output file shouldn't be created at all. If there are linking errors, it is created but then not made executable. Maybe at some point you had linking errors but not compilation errors.

(It's spelled "temperature", by the way.)

Thanks, I didn't even notice.