The code is not working. The trigonometric doesnt go in.

#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;

int main()
{
float r ;
int i ;
char ch,cho ;

cout << "Choose the trigonometric function(s): A-Sine, B-Cosine, C-Tangent, (e.g. Enter A for Sine or AC for both Sine and Tangent):";
cin >> ch;

cout << "Choose the unit of angle: A-degree or B-radian (e.g. Enter A for degree):";
cin >> cho;

cout << "- - - - - - - - - - - - - - - - - -" ;
cout << "\nAngle \t sin \t cos \t tan \n" ;
cout << "- - - - - - - - - - - - - - - - - -" ;
for(i = 0 ; i <= 180 ; i = i + 10)
{
r = i * 3.14159 / 180 ;
cout << "\n%3d \t %.2f \t %f. \t %f.\n", i, sin(r), cos(r), tan(r) ;
cout << "%f. " , sin (r);
}
cout << "\n- - - - - - - - - - - - - - - - - -\n" ;
getch() ;

return 0;
}
1
2
cout << "\n%3d \t %.2f \t %f. \t %f.\n", i, sin(r), cos(r), tan(r) ;
cout << "%f. " , sin (r);
Output in C++ doesn't work like this.
http://faculty.cs.niu.edu/~mcmahon/CS241/c241man/node83.html
you are confusing printf and cout.
printf is a C function and I often use it for doubles because it is condensed and all the data being printed is in one place.
that looks like
printf("%1.20f", sin(r));
or you can use cout, the c++ way
cout << std::setprecision(20) << sin(r);

to format several doubles in different formats requires alternating data and calls to setprecision (and maybe setwidth), which makes for very large print statements where the formatting options look exactly the same as the data being printed, so its very hard to read.
Last edited on
Topic archived. No new replies allowed.