954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

need help for programming

hello, i need the help for computer programming in the class.

the question is below. i try to write the program, but it comes out a lot of error. please, help me to do this problem.

Write a C++ program for the function

f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3

Create an array with elements:

-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3

Compute the value of f1(x) for each element of the array.
Display results in a table:


element value f1(x)
--- --------------------------------------
0 -4.3


therefore, i start the program like

#include
#include
#include
using namespace std;

void msort(float y[],int);

int main()
{
const int size=8;
float arry[size]={-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3},i;
cout<<"element: "<

sweetbaby
Newbie Poster
2 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

Please use code tags.
^ in C++ is not number to the whatever power it is the bitwise OR. What you could do is write your own pow function eg.

float myPow(float value,int power)
{
  int i = 0;
  float tempValue = value;
  for(i = 1; i < power; i++)
  {
    
    value = value * tempValue;
    
  }
  
  return value;
}

As for your code if you want size to be global declare it outside of main, or you could pass it to msort as a const parameter. The rest I not going to bother reading cause its a pain without code tags

prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You