need help to logically lay out program
I need to have the user input a degree calculate the sin, cos, and tan, then increment the user input degree by 15 for a total of 225 or 15 increments. The code below works fine, my concern lies with my numerous functions for the 16 lines of output I need to generate to the screen. I think an array would be the answer but I am not sure how to populate the array with inc or even how to call the array element to the function, but I am sure I can figure out how to do that, if indeed this is the best solution. Any suggestions would be grateful. I do not want this to be down for me, I do enjoy a challenge, but I seem to have just frustrated myself into submission. Thanks in advance for taking time to read this.
//-------------------------Preprocessor Directives------------------------------
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define RAD 57.295779
//---------------------Function Prototype Declaration---------------------------
int getfdeg(void);
float getfrad(int deg);
float getfsin(float rad);
float getfcos(float rad);
float getftan(float rad);
int getfinc (int deg);
float getfincsin (int inc);
float getfinccos (int inc);
//----------------------------Function Main-------------------------------------
main()
{
//--------------------------Declare Variables-----------------------------------
int deg;
float rad;
float sin;
float cos;
float tan;
int inc;
//---------------Input Variables-------------
clrscr();
//----------Data Manipulation Variables-------
//------------Function Calls----------------
deg = getfdeg();
printf(" %d", deg);
rad = getfrad(deg);
printf(" %f",rad);
sin = getfsin(rad);
printf(" %f",sin);
cos = getfcos(rad);
printf(" %f", cos);
tan = getftan(rad);
printf(" %f", tan);
inc = getfinc (deg);
printf("\n %d", inc);
rad = getfrad(inc);
printf(" %f",rad);
sin = getfsin(rad);
printf(" %f",sin);
cos = getfcos(rad);
printf(" %f", cos);
tan = getftan (rad);
printf(" %f", tan);
//--------------Output Variables--------------
//-----------------------User Input Statements----------------------------------
//-------------------------Output Statements------------------------------------
getch();
}
//----------------------End of Function Main()----------------------------------
//************************************************** ****************************
//****************User Defined Function Definitions*****************************
//************************************************** ****************************
//*************************user definition of getfdeg()************************
int getfdeg(void)
{
//purpose: to have user input a degree to be evaluated
//argument: void
//return type: int
int getfdeg;
printf("Please enter the degree to be evaluated then press enter.\t");
scanf(" %d", &getfdeg);
return getfdeg;
}
//*********************user defintion of getfrad(int deg)************************
float getfrad(int deg)
{
//purpose: to covert degrees into radians for trig functions
//argument: deg
//return type: float
float getfrad;
getfrad = deg/RAD;
return getfrad;
}
//*******************user definition of getfsin(float rad)**************************
float getfsin(float rad)
{
//purpose: to evaluate the sine of rad
//argument: rad
//return type: float
float getfsin;
getfsin= sin(rad);
return getfsin;
}
//***********************user definition of getfcos(rad)*****************************
float getfcos(float rad)
{
//purpose: to evaluate the cosine of rad
//arguement: rad
//return type float
float getfcos;
getfcos = cos(rad);
return getfcos;
}
//******************************user definition of getftan(rad)************************
float getftan(float rad)
{
//purpose: to evaluate the tan of rad
//arguement: rad
// return type: float
float getftan;
getftan = tan(rad);
return getftan;
}
//***************************user definiton of gfloop(deg)******************************
int getfinc (int deg)
{
//Purpose: to increment the user inputed degree by 15
//argument: deg
//return type: int
int getfinc;
getfinc = deg + 15;
return getfinc;
}
Prelude, thanks for the help
I do appreciate the time you took to reply to the post. That was exaclty what I was looking for. I have a tendency to over-use functions, as you correctly pointed out. I am having a difficult time really grasping arrays, which I believe furthers my dependency on fuctions. Well thanks again.