Alright this what I have at the moment and it is giving me what I want, now I just need to make sure that it is what I am supposed to do. Here is it is.
Code:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/*======================Functions==========================*/
int getyn(char *msg);
int getcode(void);
double getsales(void);
void error(void);
void initcosts(char *ary);
void report(char ary[][100], double *constant);
void getaverage(double *sales, double *num1, double *num2);
/*======================================================*/
/*======================================================*/
int main( )
{
char name[][100] = {"Larry Lister", "Sue Sales ", "Eva Escrow ",
"Morley Money", "Pete Profit"};
double totsales[6] = {0};
double sale, tot, avg;
int code, choice;
do
{
printf("\n\t\tRocklin Realty\n\n\n");
code = getcode( );
sale = getsales( );
totsales[ code - 1 ] += sale;
choice = getyn("\nAnother");
}
while (choice != 'N');
report(name, totsales);
getaverage(totsales, &tot, &avg);
printf("\nTotal=\t\t\t\t%22.2lf", tot);
printf("\nAverage=\t\t\t%22.2lf\n", avg);
return 0;
}
/*====================================================== */
void getaverage(double *sales, double *num1, double *num2)
{
int i;
for (i = 0; i < 5; i++)
{
*num1 += *(sales + i);
*num2 += (*(sales + i) / 5);
}
}
/*======================================================*/
void report(char ary[][100], double *constant)
{
int i;
printf("\n\nRealtor\t\t\t\t\tTotal Sales ($)\n\n");
for (i = 0; i < 5; i++)
{
printf("%s\t\t%22.2lf\n", ary[i], *(constant + i));
}
}
/*======================================================*/
int getcode(void)
{
int key, err;
do
{
printf("\nPlease enter your code:");
scanf("%d%*c", &key);
err = (key < 1) || (key > 5);
if (err) error();
}
while (err);
return (key);
}
/*======================================================*/
double getsales(void)
{
double dollar;
printf("Please enter your sale:$");
scanf("%lf%*c", &dollar);
return (dollar);
}
/*======================================================*/
int getyn(char *msg)
{
int c;
printf("%s (Y/N):", msg);
c = getchar( );
c = toupper(c);
return c;
}
/*======================================================*/
void error(void)
{
printf("\n\tYour code is invalid\n");
printf("\tPlease try another code");
}
/*======================================================*/
void initcosts(char *ary)
{
int i;
for (i = 1; i < 6; i++ )
ary[i] = 0;
}
/*======================================================*/
yes codeform works very nice, makes the code much easier to read.
Oh and do i need all of 4 of the header files?