Hello I am writing a program that gets the minimum(xmin) and maximum value(xmax) of x from the user and then evaluates an equation over the range of values between the minimum value and maximum value.
Equation: f(x) = 0.0572*cos(4.667*x) + 0.0218*pi*cos(12.22*x);
Then the program has to display a table showing the x values and y values. I need to have at least 20 values, so assuming the user enters xmin as -2 and xmax as 2 and the number of values should be 21, the increment will be 0.2.
This is what i have so far:
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
constint rows = 20;
constdouble pi = 3.1416;
double xmin, xmax, x, y, increment, value, result, a;
cout << "Enter the minimum value of x";
cin >> xmin;
cout << "Enter the maximum value of x"; n h
cin >> xmax;
increment = (xmax - xmin) / rows;
for ( a = 1; a <= 20; a++);
{
y = 0.0572 * cos(4.667 * x) + 0.0218 * pi * cos(12.22 * x);
result = value[a];
x+= increment;
}
}
I am just having problems storing the 20 numbers in an array because when i execute the program i get the error "invalid types 'double[double]' for array subscript".
I haven't understood your clearly so I can help you only to compile the program.
a should be declared as int because index of particular element of array can not be double.
You haven't declared value as an array, it should be double ... value[20]
This will fix that error.
Indexing starts from 0 so for loop should look like this for (a = 0; a < 20; a++);
Thanks for the replies. I made the necessary changes and the error is not showing up now. Now I have to enter the 20 pairs of x and y values into a table. This is my updated code:
I am required to use the value 3.1416 for pi.
Other than that I followed the things you said but I am still getting incorrect output from my program. Here is the updated version: