2016-10-09 81 views
-1
#include <stdio.h> 
#include <math.h> 

double computeTemp(double, double, double, double, double, double); 

void main(void) 
{ 

double rm,deg,h,w,l,t; 
    double final_temp; 

    printf("For all calculations assume that pressure is constant at 101.325kPa,and the heat capacity of air is also constant at 0.718kJ/kg*K\n"); 
    printf("Please enter the number of students in the room:\n"); 
    scanf("%lf",&rm); 
    printf("Please enter a temperature in degrees Celcius:\n"); 
    scanf("%lf",&deg); 
    printf("Please enter the height of the room in metres (m):\n"); 
    scanf("%lf",&h); 
    printf("Please enter the width of the room in metres (m):\n"); 
    scanf("%lf",&w); 
    printf("Please enter the length of the room in metres (m):\n"); 
    scanf("%lf",&l); 
    printf("Please enter a time in minutes (min.):\n"); 
    scanf("%lf",&t); 

    final_temp = computeTemp(rm,deg,h,w,l,t,final_temp); 

    printf("Number of students: %f\n",rm); 
    printf("Initial temperature in degrees Celcius: %f\n",deg); 
    printf("Height of room (m): %f\n",h); 
    printf("Width of room (m): %f\n",w); 
    printf("Length of room (m): %f\n",l); 
    printf("Time elapsed (min.):%f\n",t); 
    printf("Final Temperature in degrees Celcius: %f\n",final_temp); 

} 

double computeTemp(double num1, double num2, double num3, double num4, double num5, double num6) 

{ 

double temp; 

    temp = ((101.325*28.97)*(num3*num4*num5))/8.314*(num2+273.15); 
    temp = temp*0.718; 
    temp = (((4.8*num1*num6)*(num2+273.15))/(temp)); 
    temp = temp+(num2+273.15); 
    temp = temp-273.15; 
    return(temp); 
} 

我從函數調用刪除了一個double,並且出現了computeTemp參數太少的錯誤。我是新來的C語言編程,並使用代碼塊,這樣可以幫助我解決這個問題的任何信息將是非常讚賞錯誤:「computeTemp」的衝突類型(C)

+0

PLZ使用CTRL + K縮進你的代碼 –

+2

你的'computeTemp'的參數命名方案並不好。如果您不確切知道該功能在做什麼,則無法理解它。請使用更多描述性名稱。另外,請儘量避免[幻數](https://en.wikipedia.org/wiki/Magic_number_(編程))。 –

回答

3

你向前聲明聲明computeTemp作爲

double computeTemp(double, double, double, double, double, double, double); 

和定義

double computeTemp(double num1, double num2, double num3, double num4, double num5, double num6) 

數它們;第一個有七個參數,而第二個只有六個...

+0

當我這樣做時出現一個新的錯誤,說明函數computeTemp – nsquared

+0

@nsquared的參數太多。請編輯您的文章並添加您已將其更改爲 –

+0

您正在調用具有太多參數的computTemp函數。根據上面的列表,您發送了七個變量。您是否正確地處理了Ben的評論 - 您需要將函數定義中的參數數量增加到7,並保持函數聲明相同。或者,如果您不需要第七個參數,請將數字減少到六,然後刪除函數調用中的第六個變量。 – cdcdcd