Concern

I was wondering if i did this right.. heres is the assignment

Write a complete C++ program, including at least one good comment, to do the following: your program will compute values of a formula that expresses y in terms of x. The formula is:
x^4 – x^3 – x + 6
Y = -------------------------------------
! x-3 ! + sqrt (5 - x)


!x - 3! mean absolute value of x - 3
sqrt ( 5-x( mean square root of (5-x)

1. The program should start by printing a message giving your name, a short description of it’s function and saying this is the output of your first program.
2. Then it should evaluate the formula starting with x = -5, going up by 0.5 each time until it reaches 3.0. therefore, it will use these values for x: -4, -3.5, …, -3, 2.5, …, -05, 0,0.5, 1,...., 2,2.5,3.

For each x value, the program should compute the corresponding Y value. It should print these values together with explanations of what the values represent. Make sure that it prints the values in a readable format. For example, in two columns, one for x and one for its corresponding Y.
Also, it should print a short message next to each Y value, saying if Y is ZERO (0), POSITIVE(+) or NEGATIVE(-).

A typical line of output would look like this (or the values of x and y can appear underneath column headings):
X = -2 Y = 0 Y IS ZERO //(actually this one will not be zero)

3. Once you have finished using x = 3.0, the program should print again in one new row all the numbers between the last Y value and 0, with difference of 1 between each other.

Heres what i have..

# include <iostream>
# include <cmath>
using namespace std;
int main (){


double x, y;
for(x=-4; x<=3; x=x+0.5){

double za,ze,zi;
double ez,ed;
double er;
//numerator values
za = pow((x),4);
ze = pow((x),3);
zi = ((x)+6);
//denominator values
er = abs(x-3);
ez = 5;
ed = sqrt(5.0-x);

y=(za-ze-zi)/(er+ez*ed);
cout.setf(ios::right);
cout.width(6);


cout<<"x = "<<x<<" "<<"\t y = "<<y<<" "<<"\tY is ";
if(y<0)
cout<<"Negative"<<endl;
if(y==0)
cout<<"Zero"<<endl;
if(y>0)
cout<<"Positive"<<endl;
}
cout<<endl<<"________________________________________________________________________________"<<endl<<endl;
cout<<"Printing the values between the last Y and Zero:"<<endl<<endl<<endl;
//printing the numbers between the last y value and 0, with difference of 1 between each number
double yval;
for(yval=y; yval>=0; yval--){
cout<<yval<<"\t";
}

cout<<endl<<endl<<"____________________________________________________________________________"<<endl<<endl;
return 0;
}

Topic archived. No new replies allowed.