在c程序中重新声明为不同类型的符号

时间:2016-02-21 00:43:08

标签: c

我目前正在为学校开设一个项目。我需要创建一个由1到100之间的用户给出的温度转换图表。我不断收到错误"重新声明为不同类型的符号"而且我不确定如何解决它。我还包括了带有错误的编译器的图片。 compiler image

#include <stdio.h>

int toFahrenheit(int celOne, int fahOne);

int toCelsius(int celTwo, int fahTwo); 


int main(void) {    //main


    int tempNum;   //intialize user given temperature
    int tempNumnegative = -tempNum; //initialize negative temperature num


    //ask user for number between 1 and 100
    printf ( "\nPlease enter an odd number between 1 to 100:" );
    scanf ("%d", &tempNum);

    //If Else statement to make sure it is a number between 1 to 100 and reject other numbers

    if ( (tempNum > 100) || (tempNum < 1) ) {
        puts ( "\nError; Number must be a number between 1 to 100." );
        }

    else { 

    printf("\n____________________________");
    printf(" C\tF\t|\t|\tF\tC");
    printf("\n____________________________");

    //For loop to print 
    for ( tempNumnegative >= tempNum; tempNumnegative++ ) {
        printf("\n%d\t%d\t|\t|\t%d\t%d\n", toFahrenheit(int celOne, int fahOne) , toCelsius(int celTwo, int fahTwo));
    } 
    }
}

int toFahrenheit(int celOne, int fahOne) //function
{  

    int celOne= tempNum; //celcuis one equals the given value
    int fahOne = (9 / 5) * celOne + 32; //equation for f to c
}

int toCelsius(int celTwo, int fahTwo) //function
{

    int fahTwo = tempNum; 
    int celTwo = (5 / 9) * (fahTwo - 32); //equation for c to f 
}

1 个答案:

答案 0 :(得分:0)

您的代码中有四个重要问题

  1. 您将函数参数重新声明为局部变量。

    int toFahrenheit(int celOne, int fahOne) //function
    {  
        // Remove the type since `celOne' is already declared
        // as a function parameter.        
        celOne = tempNum; // celcuis one equals the given value
        fahOne = (9 / 5) * celOne + 32;
        return (9 / 5) * celOne + 32; // equation for f to c
    }
    
  2. 您不会从应该返回int的函数返回。

  3. 由于整数除数,toCelsuis()中的计算应该给0,将5 / 9更改为5.0 / 9.0toFahrenheit()中的错误值也是出于同样的原因。
  4. tempNum变量仅在main()中声明,因此未在任何转换函数中声明,并且完全不清楚您对tempNum的意图。