Having problems with functions in C++

Hello, I am currently in my second year in university and we're studying about C++. I am not good at computer languages and I'm really desperate looking for some help. My professor gave me a code to work on. I could really appreciate if you explain me how to do it..
For the equation:
z=((sin(x)/dC)*sqrt(m)
I have to create a function for data input then create a function which
calculates and outputs the results.

Also isn't dC=0 ? How to finish the equation if I have "c" as s constant?

I know how to write sin(x) in the program but I don't know how to connect it to the other part of the equation.

This is if sin(x)'s value is from -1 to 1.

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 0.439203, result;

result = sin(x);
cout << "sin(x) = " << result << endl;

double xDegrees = 90.0;

// converting degrees to radians
x = xDegrees*3.14159/180;
result = sin(x);

cout << "sin(x) = " << result << endl;
return 0;
}
Last edited on
The formula you were given is valid C/++ code, as long as z, x, dC, and m are defined.
I’ve no idea what your teacher asked you, but it could be a bit more complicated than what you tried so far.
create a function for data input

Doesn’t it mean you should ask the user some input?
If so, which input? ‘x’? ‘m’?
Also: (always if so) is the user expected to provide the values in degrees or in radiants?

At first sight, it seems the steps are:
- get ‘x’ (from user?)
- get ‘m’ (from user?)
- do you already know what ‘d’ and ‘C’ are?
- reckon ‘z’
- output the result (‘z’)

If so, maybe you need a bunch of functions like:
double getXAsDegreesFromUser();
double fromDegreesToRadians(double degrees);
// double fromRadiansToDegrees(double radians); ?
double calcZ(double x, double d, double C, double m);
...

So that main() would look like:
1
2
3
4
5
6
7
8
9
int main()
{
    double x { getXAsDegreesFromUser() };
    x = fromDegreesToRadians(x);

    double m { getMfromUser() };
    ...
    std::cout << calcZ(x, d, C, m) << '\n';
}

Topic archived. No new replies allowed.