Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


trying to deug this and having trouble

posthimposthim Member Posts: 15
displays a Celsius temperature

using namespace std;

//function prototypes
int getFahrenheit();
float calcCelsius(int);
int displayCelsius();

int main()
//declare variables
int fahrenheit = 0;
float celsius = 0.0;

//get input item
fahrenheit = getFahrenheit();

//calculate Celsius
celsius = calcCelsius(fahrenheit);

//display output item
cout << fixed;
cout << "Celsius: " << celsius << endl;
return 0;
} //end of main function

//*****program-defined functions*****

int getFahrenheit()
int tempF = 0;
cout << "Enter Fahrenheit temperature: ";
cin >> tempF;
return tempF;
} //end of getFahrenheit function

float calcCelsius(int tempFahrenheit)
float tempC = 0.0;
tempC = 5.0 / 9.0 * (tempFahrenheit - 32);
return tempC;
} //end of calcCelsius function

int temp;
cout << "Dipl temp: ";//display the temperture calculated from fehrenheit to celsius
return temp;//return celsius temperature
} //end of dsiplayCelsius function


  • Geeth AsokanGeeth Asokan Member Posts: 127

    Try this! I modified your program and it works.


    // Function prototypes
    float calcCelsius(float);

    void main(void)
    // Declare the variables
    // Temperature in Fahrenheit
    float tempF;

    // User enters temperature in fahrenheit
    cout << "Enter fahrenheit temperature: ";
    cin >> tempF;

    // This converts Fahrenheit temperature into Celsius
    // temperature


    // Display the celsius temperature
    cout << tempF << " in fahrenheit is " << calcCelsius(tempF)
    << " in celsius


    //*****Program-defined functions*****

    // Conversion program from fahrenheit into celsius
    float calcCelsius(float tempF)
    // Temperature in Celsius
    float Celsius;
    Celsius = 5.0/9.0*(tempF-32);

    Hope this helps,
  • ShelleybeanzShelleybeanz Member Posts: 7
    Seems to me that your program already works. Just needed to get rid of that warning by initializing the temp variable to zero...
  • Shawn CarterShawn Carter Member Posts: 0

    ____ < /> free video tutorials and ebooks about \ Visual Basic .NET, Perl, C++, Go, Swift, JavaScript, Delphi, C, C#, Java, MATLAB, PHP, Assembly, PL/SQL, Python, Objective-C, Scratch, Visual Basic, Ruby, R Erlang, Bash, ML, Apex, D, VBScript, Awk, Julia, F#, Kotlin, Prolog, FoxPro, Hack, Crystal, Scheme, LabVIEW, Lisp, Fortran, SAS, Ada, Lua, Dart, ABAP, COBOL, Rust, Logo, Clojure, Alice, Scala, Transact-SQL \ ___

Sign In or Register to comment.