remove action on invalid user entry

This program needs to state "Invalid entry" when the user input is outside the parameters set. It does this, but also posts the answer. How do I make it stop giving the F-C conversion when a user enters an invalid integer?

//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;
}
 
if (Fahrenheit <= 250 || Fahrenheit >= -250) 

Your if statement is faulty. You want an and condition, not an or condition.
A value of +300 is going to satisfy Fahrenheit >= -250 making the if condition true.
Likewise a value of -300, is going to satisfy Fahrenheit <= 250 also making the if condition true.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.
Thanks for your help and timely answer. Sorry for not using tags. This is all very new to me!

PS: Thanks for not being a jerk about it.
Last edited on
Topic archived. No new replies allowed.