Hi, I am writing C++ program for displaying a table of tangents given the lower and upper limits. The program initially rounds off ( e.g if one enters 29.58 and 30.33, it rounds off it to 29.6 and 30.3), and output the result in a table form. I have this problem with displaying the table completely and correctly, it was challenging for me to figure out where was I going wrong? Can you please help me out with it. When I entered, 29.58 30.33 it stops at 30.2, for 32 34, it stops at 33.9 but when I entered 84.14 84.44 and 89.44 89.48 it gives me correct table. I am enlcosing the code that I wrote. Thanks, Nagu
#include <iostream.h> #include <iomanip.h> #include <math.h> void main() { double min_Value, max_Value; const double degtoRad = M_PI/180; double diff; int num_rows = 0; cout<<"\n\n\t This program will generate tables of tangents."; cout<<"\n\t (Enter a number >= 90 or < 0, or numbers in the wrong order, to terminate.)\n\n"; for (int i = 1;i<=10;i++) { cout<<"\t ***"; } cout<<"\n\n\t Minimum and maximum values for left column of table : "; cin>>min_Value>>max_Value; cout<<setiosflags(ios::fixed|ios::showpoint); while(min_Value<=max_Value && min_Value>=0 && max_Value>=0 && min_Value<90 && max_Value<90) { min_Value = floor(min_Value*10+0.5)/10.0; max_Value = floor(max_Value*10+0.5)/10.0; cout<<"\n\n\t\t\t\t Partial Table of Tangents"; cout<<"\n\t\t "; for (int i = 0;i<=9;i++) { cout<<setw(8)<<i<<" "; } cout<<"\n\t"; for (int j = 1;j<=100;j++) { cout<<"-"; } // cout<< "\n\t " << min_Value << " " << max_Value; while(min_Value <= max_Value) { cout<<"\n\t"<<setprecision(2)<<setw(8)<<min_Value<<"| "; for (int col = 0;col<=9;col++) { cout<<setprecision(4)<<setw(8)<<tan((min_Value + col*0.01)*degtoRad)<<" "; } min_Value = min_Value+0.1; } //cout<<"\n\t "<<min_Value<<" "<<max_Value; min_Value = max_Value = 0; cout<<"\n\n\t Minimum and maximum values for left column of table : "; cin>>min_Value>>max_Value; // num_rows = 0; } }