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;
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.
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
}