Run-Time Check Failure #3 - The variable is being used without being initialized.

Why do I keep getting "Run-Time Check Failure #3 - The variable 'Fahrenheit' is being used without being initialized"? Also, it will not loop or follow the conditional statements. I'm new to programming as a whole and am having a brain fog kind of day so please, be kind, speak slowly, and use small words. Thanks!

//Farenheit to Celcius
#include <iostream>
#include <string>
#include <iomanip>
using std::cout;
using std::endl;
using std::showpos;
using std::setw;
using namespace std;
using std::fixed;
char ans;


int main()
{
double Fahrenheit;
double Celsius;

cout << fixed;
cout << setprecision (2);
cout << showpos;
Celsius = (Fahrenheit - 32)* 5.0/9.0;

cout << "Enter Degrees Fahrenheit";
cin >> Fahrenheit;
cout << endl;

if(Fahrenheit <= 250 || Fahrenheit >= -250)
cout << "Celsius = " << Celsius << endl;

else cout << "Incorrect value. Please try again.";


cout << "Would you like to enter another value? Enter 'y' to continue.";
cin >> ans;

if (ans == 'y' || ans == 'Y')
return 27;
else cout << "Have a nice day!";

system("pause");
return 0;
}


Last edited on
Why do I keep getting...The variable 'Fahrenheit' is being used without being initialized

Because you're using the variable Fahrenheit before you initialize it. You create the variable with the line double Fahrenheit; You use it on the line
Celsius = (Fahrenheit - 32)* 5.0/9.0; At no point in between do you put a value into the variable. You don't put anything into Fahrenheit until a few lines later:
cin >> Fahrenheit; I would move the line that does the calculation below the line that gets the input from the user.
Last edited on
Thanks! I fixed that and some other parts. The only issue I have now is that the answer still computes with the invalid entry.
//Farenheit to Celcius
#include <iostream>
#include <string> //allows string inclusion
#include <iomanip> //allows manipulator
using std::cout;
using std::endl;
using std::showpos; //shows positive sign
using std::setw; //allows set w/ iomanip
using namespace std;
using std::fixed;
char ans; //assigns ans as character for loop do...while statement

int main()
{
cout <<
do //begins do statement
{
double Fahrenheit;
double Celsius;

cout << fixed;
cout << setprecision (2); //sets decimal point to 2
cout << showpos; //shows positive sign for positive integers


cout << "Enter Degrees Fahrenheit "; //gives directions to user for input
cin >> Fahrenheit; //sets value of fahrenheit
cout << endl; //creates a break in the lines

if (Fahrenheit <= 250 || Fahrenheit >= -250) //conditional values for user input
{
Celsius = (Fahrenheit - 32)* 5.0/9.0; //output formula
cout << "Celsius = " << Celsius << endl; //shows conversion answer
}

else (Fahrenheit >250 || Fahrenheit <-250); //conditional values for user input
{
cout << "Invalid entry.";
}

cout << "Would you like to enter another value? Enter 'y' to continue. "; //user prompt
cin >> ans; //sets answer for action
}
while (ans == 'y'); //assigns answer values for action
{
return 30; //returns to line 30 to reprompt for F value.
system("PAUSE"); //prevents screen closure
}


return 0;
}
Last edited on
1
2
3
4
else (Fahrenheit >250 || Fahrenheit <-250); //conditional values for user input
{
    cout << "Invalid entry.";
}
is not correct. It should instead be
1
2
3
4
else
{
    cout << "Invalid entry.";
}
Topic archived. No new replies allowed.