Please help!

Please forgive me, I am a complete noob that needs help with this program.

The intention of this program is to retrieve a low and high temperature and an increment to increase the low temperature until the high temperature is reached. My main function works until I include the second (FtoC or CtoF) function. The displayFtoCtable and displayCtoFtable functions work just fine. What am I doing wrong.


#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int topChoices; // global variables

void displayMenu(); // Functions
void getMenuSelection();
void getStartEndAndIncrement();
void CtoF(int x, int y , int z);
void displayCtoFtable(int lo, int hi, int gap);
void FtoC(int x, int y , int z);
void displayFtoCtable(int lo, int hi, int gap);


int main ()
{

int lo, hi, x, y, z; // local variables
int gap;


do
{
displayMenu();
cin >> topChoices;
cout << endl;

switch (topChoices)
{
case 1: // menu choice for converting Celcius to Farenheit
cout << "Celcius to Farenheit" <<endl;
cout << endl;
cout << "Enter low temperature: " <<endl;
cin >> lo;
cout << "Enter high temperature: " <<endl;
cin >> hi;
cout << "Enter temperature increment: " <<endl;
cin >> gap;
CtoF (x, y, z); ---- THIS IS CAUSING ERROR
cout << endl;
displayCtoFtable(lo,hi,gap);
cout << endl;
break;

case 2: // menu choice for converting Frenheit to Celcius
cout << "Farenheit to Celcius" <<endl;
cout << endl;
cout << "Enter low temperature: " <<endl;
cin >> lo;
cout << "Enter high temperature: " <<endl;
cin >> hi;
cout << "Enter temperature increment: " <<endl;
cin >> gap;
FtoC (x, y, z); ----- THIS IS CAUSING ERROR
cout << endl;
displayFtoCtable(lo,hi,gap);
cout << endl;
break;

case 9: // menu choice for ending program
cout << endl;
break;

default:
cout << "Invalid Input" <<endl;
}



}
while (topChoices != 9);


cin.ignore(1);
return 0;
}

void displayMenu() //Menu Function
{
cout << "Enter -- " <<endl;
cout << "Press 1 to convert from Celcius to Farenheit." <<endl;
cout << "Press 2 to convert from Farenheit to Celcius." <<endl;
cout << "Press 9 to exit." <<endl;
}


void CtoF(int x,int y, int z) //convert celcius to farenheit
{
cout << "TABLE CF calc" << endl;
}

void displayCtoFtable(int lo, int hi, int gap) // display table with celcius and farenheit values
{
cout << "TABLE CF" << endl;
}

void FtoC(int x,int y, int z) //convert farenheit to celcius
{
cout << "TABLE FC calc" << endl;
}

void displayFtoCtable(int lo, int hi, int gap) // display table with farenheit and celcius values
{
cout << "TABLE FC" << endl;
}
I'm not quite sure what your asking, thew functions run just fine for me.
This code compiles with a few warnings but will not run once the CtoF or FtoC functions are implemented. I have indicated where the code crashes in the original post.

Here are the 3 warnings:

1>y:\d03467176\documents\visual studio 2008\projects\week5practice1\week5practice1\week5practice1.cpp(41) : warning C4700: uninitialized local variable 'z' used
1>y:\d03467176\documents\visual studio 2008\projects\week5practice1\week5practice1\week5practice1.cpp(41) : warning C4700: uninitialized local variable 'y' used
1>y:\d03467176\documents\visual studio 2008\projects\week5practice1\week5practice1\week5practice1.cpp(41) : warning C4700: uninitialized local variable 'x' used

This is the crash dialogue:

Run-Time Check Failure #3 - The variable 'z' is being used without being initialized.
ok, your problem is you are trying to use variables without giving them a vlaue first.
that's what "uninitialized" means.

first you have to initialize each variable, i.e give it a value:

 
z=2;
The reason for these warnings is that you declare the variables x, y and z:
int lo, hi, x, y, z;
But you don't put any particular value in them before you use them. This may well result in unexpected behaviour.

PS: If you get warnings, you shouldn't ignore them even if it does run. Those warnings are basically there to warn you that the run time error that you got is possible with your code. So, the moral is don't ignore warnings unless you are sure that you are safe ignoring them!
Thank you for your help!
Topic archived. No new replies allowed.