#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main ()
{
//declare variables
double x; //number input by user
cout<< "Please enter a number to use as x"<<endl;
cin>> x;
cout<< "x= " << x << endl;
double y; //number solving for
if ((-3<=x) && (x<=2))
{
y=(x*x)+(2*x)-3;
}
else if ((2<x) && (x<=10))
{
y=(5*x)+7;
}
else if (x<-3)//first part of third parameter
{
y=0;
}
else if (x>10)//second part of third parameter
{
y=0;
}
cout << "y= "<< y ;
cout<< setprecision(3) << y <<endl;
return 0;
}
I am trying to find y. For some reason when entering an X that is <-3 or >10 it does not give me 0 like I would like it to. could anyone help?