Hello everyone,
I have some problems with this program that does very basic calculations.
Code:
#include <stdio.h>
#define true 1
#define false 0
void displayMenu(void);
char getOption(void);
void calculations(void);
void calculationsSubMenu(void);
void calcEPS(void);
typedef struct
{
float npat[5];
float eps[5];
int total;
}data_struct;
int main()
{
}
void displayMenu(void)
{
}
char getOption(void)
{
}
void calculationsSubMenu(void)
{
}
void calculations(void)
{
}
void calcEPS (void)
{
int issue;
int ch,counter,i;
char name[20];
data_struct data;
printf("\n\n\n\n FUNDAMENTAL ANALYSIS TEST PROGRAM\n");
printf("\nPlease enter the name of the company: ");
gets(name);
printf("\nhow many would you like to calculate? : ");
scanf("%d", &data.total);
for (i= 0; data.total > i; i++)
{
counter++;
printf("\n\n EPS %d ", counter);
printf("\n Earnings Per Share\n\n");
printf("Please enter the net profit after tax(NPAT): ");
scanf("%f", &data.npat);
printf("\nPlease enter the number of shares on issue: ");
scanf("%d", &issue);
data.eps[i] = data.npat[i] / issue;
getchar();
printf("\n");
}
printf("\nthe last %d calculations for %s are", name, counter);
counter =0;
for (i = 0; data.total >i; i++)
{
counter++;
printf("\n%d EPS is %0.5f ", counter, data.eps[i]);
}
printf ("\n\nPress [Enter] to continue");
while ((ch = getchar()) != '\n' && ch != EOF);
}
I have deleted all the menu code i dont think is needed.
I have a few problems.
1) the program crashes after doing a few large EPS calculations. I am using floating point data type which i thought could handle the large numbers..maybe not?
2) related to #1 my array
Code:
typedef struct
{
float npat[5];
float eps[5];
int total;
}data_struct;
maybe im mistaken how arrays work, but i only want a max of 5 years to be stored (i know this is not checked). But it seems when if i make it float eps[100], or float eps[500] the program can handle more calculations before crashing.
3) I cant seem to get the name to display correctly, it is all garbage. not sure why this doesnt work as the function works perfectly as a seperate program.
sorry for the long post, any help would be appreciated.
Andrew