What's new

C & C++ Patulong po sana sa C++ code po

Paul Sernine

Addict
Joined
Apr 1, 2021
Posts
159
Solutions
1
Reaction
56
Points
109
Patulong sana ako lodi kung ano po mali ko dito.

#include <iostream> using namespace std; int main() { const double PI = 3.1415926535897932384650288; //Pi accuracy double sin (double x) //Sine by Taylor's Series } double sign = 1; if (x < 0) { sign = -1.0; x = -x; } if (x > 360) x = int(x/360)*360; x *= PI/180.0; double res = 0; double term = x; int k = 1; while (res+term!=res) { res += term; k +=2 ; term *= -x*x/k/(k-1); } return sign*res; } double cos(double x) //Cosine by Taylor's Series { double sign = 1; if (x < 0) { sign = -1.0; x = -x; } if (x > 360) x -= int(x/360)*360; x *= PI/180.0; double res = 0; double term = 1; int k = 0; while (res+term!=res) { res += term; k += 2; term *= -x*x/k/(k-1); } return res; } double tan(double x) // tan(x) = sin(x)/cos(x) { double res = (sin(x)/cos(x)); if (res > 100) { res=1.0/0.0; } else if (res < -100){ res= -1.0/0.0; } return res; } double cot (double x) // cot(x) = cos(x)/sin(x) { double res = (cos(x)/sin(x)); if (res > 100) { res = 1.0/0.0; } else if (res < -100) { res = -1.0/0.0; } return res; } double sec (double x) // sec(x) = 1/cos(x) { double res = (1.0/cos(x)); if (res > 100) { res = 1.0/0.0; } else if (res < -100) { res = -1.0/0.0; } return res; } double csc(double x) // csc(x) = 1/sin(x) { double res = (1.0/sin(x)); if (res > 100) { res = 1.0/0.0; } else if (res < -100) { res = -1.0/0.0; } return res; } double x, output; int main() { char recompute = 'y'; while (recompute == 'y' || recompute == 'Y') { cout<< "\nEnter angle x:\t"; cin >> x; output = sin(x); cout << "\n sin(x)=\t" << output << endl; output = cos(x); cout << "\n cos(x)=\t" << output << endl; output = tan(x); cout << "\n tan(x)=\t" << output << endl; output = cot(x); cout << "\n cot(x)=\t" << output << endl; output = sec(x); cout << "\n sec(x)=\t" << output << endl; output = csc(x); cout << "\n csc(x)=\t" << output << endl; cout << "\n Recompute? (y/n):\t"; cin >> recompute; } //end while loop cout << "Process complete." << endl; return 0; }
 
main.cpp:8:2: error: expected unqualified-id before ‘if’
8 | if (x < 0)
| ^~
main.cpp:13:2: error: expected unqualified-id before ‘if’
13 | if (x > 360)
| ^~
main.cpp:15:2: error: ‘x’ does not name a type
15 | x *= PI/180.0;
| ^
main.cpp:17:16: error: ‘x’ was not declared in this scope
17 | double term = x;
| ^
main.cpp:19:2: error: expected unqualified-id before ‘while’
19 | while (res+term!=res)
| ^~~~~
main.cpp:25:2: error: expected unqualified-id before ‘return’
25 | return sign*res;
| ^~~~~~
main.cpp:26:1: error: expected declaration before ‘}’ token
26 | }
| ^
main.cpp: In function ‘double cos(double)’:
main.cpp:36:7: error: ‘PI’ was not declared in this scope
36 | x *= PI/180.0;
| ^~
main.cpp: In function ‘double tan(double)’:
main.cpp:50:16: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
50 | double res = (sin(x)/cos(x)); if (res > 100)
| ^~~
| sign
main.cpp: In function ‘double cot(double)’:
main.cpp:61:23: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
61 | double res = (cos(x)/sin(x));
| ^~~
| sign
main.cpp: In function ‘double csc(double)’:
main.cpp:87:20: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
87 | double res = (1.0/sin(x));
| ^~~
| sign
main.cpp: At global scope:
main.cpp:99:5: error: redefinition of ‘int main()’
99 | int main()
| ^~~~
main.cpp:3:5: note: ‘int main()’ previously defined here
3 | int main()
| ^~~~
main.cpp: In function ‘int main()’:
main.cpp:106:11: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
106 | output = sin(x);
| ^~~
| sign

ito nakita ko lods
pa up ung my mga compiler dyan or pwede mo i paste sa online meron mga online compiler na website google mo nalang

You do not have permission to view the full content of this post. Log in or register now.
 
main.cpp:8:2: error: expected unqualified-id before ‘if’
8 | if (x < 0)
| ^~
main.cpp:13:2: error: expected unqualified-id before ‘if’
13 | if (x > 360)
| ^~
main.cpp:15:2: error: ‘x’ does not name a type
15 | x *= PI/180.0;
| ^
main.cpp:17:16: error: ‘x’ was not declared in this scope
17 | double term = x;
| ^
main.cpp:19:2: error: expected unqualified-id before ‘while’
19 | while (res+term!=res)
| ^~~~~
main.cpp:25:2: error: expected unqualified-id before ‘return’
25 | return sign*res;
| ^~~~~~
main.cpp:26:1: error: expected declaration before ‘}’ token
26 | }
| ^
main.cpp: In function ‘double cos(double)’:
main.cpp:36:7: error: ‘PI’ was not declared in this scope
36 | x *= PI/180.0;
| ^~
main.cpp: In function ‘double tan(double)’:
main.cpp:50:16: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
50 | double res = (sin(x)/cos(x)); if (res > 100)
| ^~~
| sign
main.cpp: In function ‘double cot(double)’:
main.cpp:61:23: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
61 | double res = (cos(x)/sin(x));
| ^~~
| sign
main.cpp: In function ‘double csc(double)’:
main.cpp:87:20: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
87 | double res = (1.0/sin(x));
| ^~~
| sign
main.cpp: At global scope:
main.cpp:99:5: error: redefinition of ‘int main()’
99 | int main()
| ^~~~
main.cpp:3:5: note: ‘int main()’ previously defined here
3 | int main()
| ^~~~
main.cpp: In function ‘int main()’:
main.cpp:106:11: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
106 | output = sin(x);
| ^~~
| sign

ito nakita ko lods
aww goods yan ung mga my mali dami ah hahahahah

‘sin’ was not declared in this scope; did you mean ‘sign’?

sign naka declare na variable hindi sin

double sign = 1;
 
Last edited:
1676483143215.png


dito pa lang sinarado mo na yung int main() lagay mo yung close curly bracket sa pinakadulo
 

Attachments

#include <iostream>
#include <cmath>
using namespace std;

const double PI = 3.1415926535897932384650288;

double sin(double x)
{
double sign = 1;
if (x < 0)
{
sign = -1.0;
x = -x;
}
if (x > 360)
x = int(x/360)*360;
x *= PI/180.0;
double res = 0;
double term = x;
int k = 1;
while (res+term != res)
{
res += term;
k += 2 ;
term *= -x*x/k/(k-1);
}
return sign*res;
}

double cos(double x)
{
double sign = 1;
if (x < 0)
{
sign = -1.0;
x = -x;
}
if (x > 360)
x -= int(x/360)*360;
x *= PI/180.0;
double res = 0;
double term = 1;
int k = 0;
while (res+term != res)
{
res += term;
k += 2;
term *= -x*x/k/(k-1);
}
return res;
}

double tan(double x)
{
double res = (sin(x)/cos(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

double cot(double x)
{
double res = (cos(x)/sin(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

double sec(double x)
{
double res = (1.0/cos(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

double csc(double x)
{
double res = (1.0/sin(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

int main()
{
double x, output;
char recompute = 'y';
while (recompute == 'y' || recompute == 'Y')
{
cout << "\nEnter angle x (in degrees):\t";
cin >> x;
output = sin(x);
cout << "\n sin(x)=\t" << output << endl;
output = cos(x);
cout << "\n cos(x)=\t" << output << endl;
output = tan(x);
cout << "\n tan(x)=\t" << output << endl;
output = cot(x);
cout << "\n cot(x)=\t" << output << endl;
output = sec(x);
cout << "\n sec(x)=\t" << output << endl;
output = csc(x);
cout << "\n csc(x)=\t" << output << endl;
cout << "\n Recompute? (y/n):\t";
cin >> recompute;

} //end while loop
cout << "Process complete." << endl;
return 0;
}

1676994328190.png
 

Attachments

#include <iostream>
#include <cmath>
using namespace std;

const double PI = 3.1415926535897932384650288;

double sin(double x)
{
double sign = 1;
if (x < 0)
{
sign = -1.0;
x = -x;
}
if (x > 360)
x = int(x/360)*360;
x *= PI/180.0;
double res = 0;
double term = x;
int k = 1;
while (res+term != res)
{
res += term;
k += 2 ;
term *= -x*x/k/(k-1);
}
return sign*res;
}

double cos(double x)
{
double sign = 1;
if (x < 0)
{
sign = -1.0;
x = -x;
}
if (x > 360)
x -= int(x/360)*360;
x *= PI/180.0;
double res = 0;
double term = 1;
int k = 0;
while (res+term != res)
{
res += term;
k += 2;
term *= -x*x/k/(k-1);
}
return res;
}

double tan(double x)
{
double res = (sin(x)/cos(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

double cot(double x)
{
double res = (cos(x)/sin(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

double sec(double x)
{
double res = (1.0/cos(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

double csc(double x)
{
double res = (1.0/sin(x));
if (res > 100 || res < -100)
{
res = NAN;
}
return res;
}

int main()
{
double x, output;
char recompute = 'y';
while (recompute == 'y' || recompute == 'Y')
{
cout << "\nEnter angle x (in degrees):\t";
cin >> x;
output = sin(x);
cout << "\n sin(x)=\t" << output << endl;
output = cos(x);
cout << "\n cos(x)=\t" << output << endl;
output = tan(x);
cout << "\n tan(x)=\t" << output << endl;
output = cot(x);
cout << "\n cot(x)=\t" << output << endl;
output = sec(x);
cout << "\n sec(x)=\t" << output << endl;
output = csc(x);
cout << "\n csc(x)=\t" << output << endl;
cout << "\n Recompute? (y/n):\t";
cin >> recompute;

} //end while loop
cout << "Process complete." << endl;
return 0;
}

View attachment 2528631
ano yung error paps?
 
Back
Top