here is the things so far i got.

#include <stdio.h>
int CF(int C);
int FC(int F);
int main(){
printf("Fahrenheit equivalents of Celsius temperature\n");
printf("Celsius \t Fahrenheit \n");
for (x=0;x<=100;x++);

printf("Celsius equivalents of Fahrenheit temperature\n");
printf("Fahrenheit \t Celsius \n");
for (x=32;x<=212;x++);

Pls,somebody help me.T.T

Dani AI

Generated

Common beginner problems and quick fixes (what caused the errors you saw)

  • The "Undefined symbol" messages came from using variables that were never declared; declare loop variables (for example int i;) before use. pointed this out.
  • A stray semicolon after a for(...) (for example for (x=0;x<=100;x++);) makes the loop body run zero times.
  • You declared int CF(int) and int FC(int) but did not define them — either define them before main or keep prototypes and provide definitions after main. raised this.
  • Integer arithmetic truncation (5/9 == 0) is the classic gotcha; use 9.0/5.0 or 5.0/9.0 (floating point) or cast operands to double. mentioned this.

Practical improvements to consider

  • Use double for conversion functions so you preserve fractional values, then format output with printf (for example one decimal place). If you want integer output, explicitly round with round() from <math.h> and cast to int (link with -lm on some toolchains).
  • Prefer descriptive names (c_to_f, f_to_c), declare variables at the top of main, and compile with warnings enabled (gcc -Wall) to catch undeclared identifiers and accidental semicolons.

Example (clean, floating-point table)

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

double c_to_f(double c) { return c * 9.0/5.0 + 32.0; }
double f_to_c(double f) { return (f - 32.0) * 5.0/9.0; }

int main(void) {
    int i;
    printf("Celsius    Fahrenheit\n");
    for (i = 0; i <= 100; ++i)
        printf("%3d        %6.1f\n", i, c_to_f(i));
    printf("\nFahrenheit  Celsius\n");
    for (i = 32; i <= 212; ++i)
        printf("%3d        %6.1f\n", i, f_to_c(i));
    return 0;
}

Final tip: watch types and stray semicolons, and prefer small, well-named functions — that will make the program clearer and avoid the errors you saw.

Recommended Answers

All 11 Replies

The conversion formula is:

C = (F - 32) * (5 / 9)

and

F = (C * 9 / 5) + 32

So,

for (x=0; x <= 100; x++) {
    printf("%d %d", x, CF(x));
}

int CF(int C)
{
    /* calculate the formula here and return the needed value. */
}

erm,still got 2 problem.1st,i need to put in the formula,right?where and how should i put in.2nd,is about the integer x.i also need to add x into function main right?sigh,i am newbie.a lot of basic things still dont understand.

#include <stdio.h>
int CF(int C);
int FC(int F);
int main (){

printf("Fahrenheit equivalents of Celsius temperature\n");
printf("Celsius\t\tFahrenheit\n");

for (x=0;x<=100;x++){
printf("%d\t%d\n",x,CF(x));
C = (F - 32) * (5 / 9);
}

printf("Celsius equivalents of Fahrenheit temperature\n");
printf("Fahrenheit\tCelsius\n");
for (x=32;x<=212;x++){
printf("%d\t%d\n",x,FC(x));
F = (C * 9 / 5) + 32;
}
return 0;
}

Error E2451 ass22.c 5: Undefined symbol 'C' in function main
Error E2451 ass22.c 5: Undefined symbol 'F' in function main
Error E2451 ass22.c 10: Undefined symbol 'x' in function main

You have to declare your variables, before you can use them. Generally, it's best to declare them, right at the top of the function they are used in.

how to declare?like int x?

#include <stdio.h>
int CF(int C);
int FC(int F);
int main (){
int x;

printf("Fahrenheit equivalents C=(F-32)*(5/9)\n");
printf("Celsius\t\tFahrenheit\n");
for (x=0;x<=100;x++){
printf("%d\t%d\n",x,CF(x));
}

printf("Celsius equivalents F=(C*9/5)+32;\n");
printf("Fahrenheit\tCelsius\n");
for (x=32;x<=212;x++){
printf("%d\t%d\n",x,FC(x));
}
return 0;
}

i still cant solve it.help.these r the thing i got now.

Where are your functions?
int CF(int C);
int FC(int F);

Where have you defined them?

ya,i also got notice about those 2 but how to defined?defined as what?this thing really drop me crazy.now here already 3.45am.i nd go to sleep.2moro still got class.sigh.

You need to write functions for conversions.

You have declared them, but not defined them.
int CF(int C);
int FC(int F);

Well, you can learn about functions from tutorials on the Internet, but i suggest you read a good book and learn about functions.

And keep in mind 5/9 = 0. That's integer arithmetic. You want 5.0/9.0 to get the correct answers.

Thanks a lot,guys.I manage to get the answer from my lecturer.Here is the code for ppl to refer or do as reference.

#include <stdio.h>
int CF(int C);
int FC(int F);
int main (){
int x;

printf("Fahrenheit equivalents of Celsius temperature\n");
printf("Celsius\t\tFahrenheit\n");

for (x=0;x<=100;x++){
printf("%d\t\t%d\n",x,CF(x));
}

printf("Celsius equivalents of Fahrenheit temperature\n");
printf("Fahrenheit\tCelsius\n");

for (x=32;x<=212;x++){
printf("%d\t\t%d\n",x,FC(x));
}
return 0;
}

int CF( int C){
return (int)(32+(C * 9 / 5));
}

int FC(int F){
return (int)(5.0 /9.0 *(F-32));
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.